Ton-Dynasty / ticton-v0

Innovative price oracle for TON
https://ticton.xyz
7 stars 1 forks source link

Test suite for `Tick`, `Wind`, `Ring` #2

Closed alan890104 closed 9 months ago

alan890104 commented 10 months ago

Although the reward mechanism is not implemented, its logic will not effect the basic tests. Tests include but not restricted to the below check lists, feel free to provide more testing idea here:

NOTE:

  1. remaining funds includes TON and jettons
  2. always check balance after each operation related to transfer asset

Tick

Tick message open a quote position for a watchmaker.

image

Wind

Wind message takes profit from specified Alarm contract, and open a new position with doubled assets

image

Ring

image

ipromise2324 commented 10 months ago

Tick Test:

  1. In the receive(msg: JettonTransferNotification) function of the Oracle contract, code for returning Jettons to the user was not written.
  2. In the receive(msg: JettonTransferNotification), I added a sendBackAmount variable to record how much money needs to be returned to the user after building alarm successfully. Also, I changed the mode to SendIgnoreErrors and set the value to sendBackAmount in the receive(msg: JettonTransferNotification).
  3. In the receive(msg: JettonTransferNotification), needBaseAssetAmount = msg.amount.float() / baseAssetPrice; After calculation, it needs to be multiplied by 10**9 to represent the amount of ton to be transferred (e.g., 10/2.5 = 4, which means 4 tons, therefore 4 should be multiplied by Decimal)
  4. In the Alarm contract, I modified requireNotInitialized to self.watchmaker == newAddress(0, 0). This means that if watchmaker.address == 0x00, it indicates that the alarm has not been initialized yet (originally it was judged by self.oracleAddress == newAddress(0, 0)).
ipromise2324 commented 10 months ago

Wind Test:

  1. In the receive(msg: Reset) function, I changed the require(self.remainScale > msg.buyNum, "Not enough scale to buy"); to >=, to allow the Timekeeper to buy all of the remainScale.
  2. In the receive(msg: JettonTransferNotification) function, within if(opCode == 1), the Reset message's sender is msg.sender (timekeeper), not ctx.sender (oracle jetton wallet).
  3. In the receive(msg: Chime) function, when deploying a new alarm, a basic value is required to build the contract. I have currently hardcoded it as 0.05 ton.
  4. In the receive(msg: Chime) function, after building the alarm, totalAlarms is not incremented by 1.
  5. When the timekeeper sends the wind message, it does not specify the new price to be offered, therefore there is no check to see if the jettons and tons sent are sufficient for this quotation.
  6. In the receive(msg: Reset) function, baseAssetPrice is not overwritten with a new value. It should be changed to the new price as perceived by the timekeeper. Currently, it is 0, so the baseAssetPrice for the new alarm built by the timekeeper is also 0.
  7. In the receive(msg: Chime) function, in addition to checking if msg.remainScale > 0, should there also be a check to see if the verification stage has passed? Only if it has passed, the price can be changed.
  8. In receive(msg: Reset), if require(self.remainScale >= msg.buyNum, "Not enough scale to buy") is not met, the jettons are not returned to the timekeeper.
skyline9981 commented 10 months ago
  1. Didn't check if Chronoshift is from alarm contract, so the test is failed.
  2. Didn't check the time pace when watchmaker send ring msg to the oracle.
  3. Should find a way to change blockchain logic time when testing.
ipromise2324 commented 9 months ago

Bugs:

In receive(msg: Reset):

In receive(msg: Chime):

ipromise2324 commented 9 months ago

Test Cases:

Tick Test Add:

Wind Test Add:

Ring Test Add: