You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

404 lines
15 KiB

Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
Fix eth events query and sync inconsistent state - kvdb - Fix path in Last when doing `setNew` - Only close if db != nil, and after closing, always set db to nil - This will avoid a panic in the case where the db is closed but there's an error soon after, and a future call tries to close again. This is because pebble.Close() will panic if the db is already closed. - Avoid calling pebble methods when a the Storage interface already implements that method (like Close). - statedb - In test, avoid calling KVDB method if the same method is available for the StateDB (like MakeCheckpoint, CurrentBatch). - eth - In *EventByBlock methods, take blockHash as input argument and use it when querying the event logs. Previously the blockHash was only taken from the logs results *only if* there was any log. This caused the following issue: if there was no logs, it was not possible to know if the result was from the expected block or an uncle block! By querying logs by blockHash we make sure that even if there are no logs, they are from the right block. - Note that now the function can either be called with a blockNum or blockHash, but not both at the same time. - sync - If there's an error during call to Sync call resetState, which internally resets the stateDB to avoid stale checkpoints (and a corresponding invalid increase in the StateDB batchNum). - During a Sync, after very batch processed, make sure that the StateDB currentBatch corresponds to the batchNum in the smart contract log/event.
3 years ago
  1. package eth
  2. import (
  3. "math/big"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. )
  8. const slotDeadlineConst = uint8(20)
  9. const openAuctionSlotsConst = uint16(4320)
  10. const closedAuctionSlotsConst = uint16(2)
  11. const outbiddingConst = uint16(1000)
  12. const currentSlotConst = 0
  13. const blocksPerSlot = uint8(40)
  14. const minBidStr = "10000000000000000000"
  15. const URL = "http://localhost:3000"
  16. var allocationRatioConst [3]uint16 = [3]uint16{4000, 4000, 2000}
  17. var auctionClientTest *AuctionClient
  18. func TestAuctionGetCurrentSlotNumber(t *testing.T) {
  19. currentSlot, err := auctionClientTest.AuctionGetCurrentSlotNumber()
  20. require.Nil(t, err)
  21. currentSlotInt := int(currentSlot)
  22. assert.Equal(t, currentSlotConst, currentSlotInt)
  23. }
  24. func TestAuctionEventInit(t *testing.T) {
  25. auctionInit, blockNum, err := auctionClientTest.AuctionEventInit()
  26. require.NoError(t, err)
  27. assert.Equal(t, int64(18), blockNum)
  28. assert.Equal(t, donationAddressConst, auctionInit.DonationAddress)
  29. assert.Equal(t, bootCoordinatorAddressConst, auctionInit.BootCoordinatorAddress)
  30. assert.Equal(t, "https://boot.coordinator.io", auctionInit.BootCoordinatorURL)
  31. assert.Equal(t, uint16(1000), auctionInit.Outbidding)
  32. assert.Equal(t, uint8(20), auctionInit.SlotDeadline)
  33. assert.Equal(t, uint16(2), auctionInit.ClosedAuctionSlots)
  34. assert.Equal(t, uint16(4320), auctionInit.OpenAuctionSlots)
  35. assert.Equal(t, [3]uint16{4000, 4000, 2000}, auctionInit.AllocationRatio)
  36. }
  37. func TestAuctionConstants(t *testing.T) {
  38. INITMINBID := new(big.Int)
  39. INITMINBID.SetString(minBidStr, 10)
  40. auctionConstants, err := auctionClientTest.AuctionConstants()
  41. require.Nil(t, err)
  42. assert.Equal(t, auctionConstants.BlocksPerSlot, blocksPerSlot)
  43. assert.Equal(t, auctionConstants.GenesisBlockNum, genesisBlock)
  44. assert.Equal(t, auctionConstants.HermezRollup, hermezRollupTestAddressConst)
  45. assert.Equal(t, auctionConstants.InitialMinimalBidding, INITMINBID)
  46. assert.Equal(t, auctionConstants.TokenHEZ, tokenHEZAddressConst)
  47. assert.Equal(t, auctionConstants.GovernanceAddress, governanceAddressConst)
  48. }
  49. func TestAuctionVariables(t *testing.T) {
  50. INITMINBID := new(big.Int)
  51. INITMINBID.SetString(minBidStr, 10)
  52. defaultSlotSetBid := [6]*big.Int{INITMINBID, INITMINBID, INITMINBID, INITMINBID, INITMINBID,
  53. INITMINBID}
  54. auctionVariables, err := auctionClientTest.AuctionVariables()
  55. require.Nil(t, err)
  56. assert.Equal(t, auctionVariables.AllocationRatio, allocationRatioConst)
  57. assert.Equal(t, auctionVariables.BootCoordinator, bootCoordinatorAddressConst)
  58. assert.Equal(t, auctionVariables.ClosedAuctionSlots, closedAuctionSlotsConst)
  59. assert.Equal(t, auctionVariables.DefaultSlotSetBid, defaultSlotSetBid)
  60. assert.Equal(t, auctionVariables.DonationAddress, donationAddressConst)
  61. assert.Equal(t, auctionVariables.OpenAuctionSlots, openAuctionSlotsConst)
  62. assert.Equal(t, auctionVariables.Outbidding, outbiddingConst)
  63. assert.Equal(t, auctionVariables.SlotDeadline, slotDeadlineConst)
  64. }
  65. func TestAuctionGetSlotDeadline(t *testing.T) {
  66. slotDeadline, err := auctionClientTest.AuctionGetSlotDeadline()
  67. require.Nil(t, err)
  68. assert.Equal(t, slotDeadlineConst, slotDeadline)
  69. }
  70. func TestAuctionSetSlotDeadline(t *testing.T) {
  71. newSlotDeadline := uint8(25)
  72. _, err := auctionClientTest.AuctionSetSlotDeadline(newSlotDeadline)
  73. require.Nil(t, err)
  74. slotDeadline, err := auctionClientTest.AuctionGetSlotDeadline()
  75. require.Nil(t, err)
  76. assert.Equal(t, newSlotDeadline, slotDeadline)
  77. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  78. require.Nil(t, err)
  79. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  80. require.Nil(t, err)
  81. assert.Equal(t, newSlotDeadline, auctionEvents.NewSlotDeadline[0].NewSlotDeadline)
  82. }
  83. func TestAuctionGetOpenAuctionSlots(t *testing.T) {
  84. openAuctionSlots, err := auctionClientTest.AuctionGetOpenAuctionSlots()
  85. require.Nil(t, err)
  86. assert.Equal(t, openAuctionSlotsConst, openAuctionSlots)
  87. }
  88. func TestAuctionSetOpenAuctionSlots(t *testing.T) {
  89. newOpenAuctionSlots := uint16(4500)
  90. _, err := auctionClientTest.AuctionSetOpenAuctionSlots(newOpenAuctionSlots)
  91. require.Nil(t, err)
  92. openAuctionSlots, err := auctionClientTest.AuctionGetOpenAuctionSlots()
  93. require.Nil(t, err)
  94. assert.Equal(t, newOpenAuctionSlots, openAuctionSlots)
  95. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  96. require.Nil(t, err)
  97. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  98. require.Nil(t, err)
  99. assert.Equal(t, newOpenAuctionSlots, auctionEvents.NewOpenAuctionSlots[0].NewOpenAuctionSlots)
  100. }
  101. func TestAuctionGetClosedAuctionSlots(t *testing.T) {
  102. closedAuctionSlots, err := auctionClientTest.AuctionGetClosedAuctionSlots()
  103. require.Nil(t, err)
  104. assert.Equal(t, closedAuctionSlotsConst, closedAuctionSlots)
  105. }
  106. func TestAuctionSetClosedAuctionSlots(t *testing.T) {
  107. newClosedAuctionSlots := uint16(1)
  108. _, err := auctionClientTest.AuctionSetClosedAuctionSlots(newClosedAuctionSlots)
  109. require.Nil(t, err)
  110. closedAuctionSlots, err := auctionClientTest.AuctionGetClosedAuctionSlots()
  111. require.Nil(t, err)
  112. assert.Equal(t, newClosedAuctionSlots, closedAuctionSlots)
  113. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  114. require.Nil(t, err)
  115. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  116. require.Nil(t, err)
  117. assert.Equal(t, newClosedAuctionSlots,
  118. auctionEvents.NewClosedAuctionSlots[0].NewClosedAuctionSlots)
  119. _, err = auctionClientTest.AuctionSetClosedAuctionSlots(closedAuctionSlots)
  120. require.Nil(t, err)
  121. }
  122. func TestAuctionGetOutbidding(t *testing.T) {
  123. outbidding, err := auctionClientTest.AuctionGetOutbidding()
  124. require.Nil(t, err)
  125. assert.Equal(t, outbiddingConst, outbidding)
  126. }
  127. func TestAuctionSetOutbidding(t *testing.T) {
  128. newOutbidding := uint16(0xb)
  129. _, err := auctionClientTest.AuctionSetOutbidding(newOutbidding)
  130. require.Nil(t, err)
  131. outbidding, err := auctionClientTest.AuctionGetOutbidding()
  132. require.Nil(t, err)
  133. assert.Equal(t, newOutbidding, outbidding)
  134. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  135. require.Nil(t, err)
  136. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  137. require.Nil(t, err)
  138. assert.Equal(t, newOutbidding, auctionEvents.NewOutbidding[0].NewOutbidding)
  139. _, err = auctionClientTest.AuctionSetOutbidding(outbiddingConst)
  140. require.Nil(t, err)
  141. }
  142. func TestAuctionGetAllocationRatio(t *testing.T) {
  143. allocationRatio, err := auctionClientTest.AuctionGetAllocationRatio()
  144. require.Nil(t, err)
  145. assert.Equal(t, allocationRatioConst, allocationRatio)
  146. }
  147. func TestAuctionSetAllocationRatio(t *testing.T) {
  148. newAllocationRatio := [3]uint16{3000, 3000, 4000}
  149. _, err := auctionClientTest.AuctionSetAllocationRatio(newAllocationRatio)
  150. require.Nil(t, err)
  151. allocationRatio, err := auctionClientTest.AuctionGetAllocationRatio()
  152. require.Nil(t, err)
  153. assert.Equal(t, newAllocationRatio, allocationRatio)
  154. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  155. require.Nil(t, err)
  156. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  157. require.Nil(t, err)
  158. assert.Equal(t, newAllocationRatio, auctionEvents.NewAllocationRatio[0].NewAllocationRatio)
  159. _, err = auctionClientTest.AuctionSetAllocationRatio(allocationRatioConst)
  160. require.Nil(t, err)
  161. }
  162. func TestAuctionGetDonationAddress(t *testing.T) {
  163. donationAddress, err := auctionClientTest.AuctionGetDonationAddress()
  164. require.Nil(t, err)
  165. assert.Equal(t, &donationAddressConst, donationAddress)
  166. }
  167. func TestAuctionGetBootCoordinator(t *testing.T) {
  168. bootCoordinator, err := auctionClientTest.AuctionGetBootCoordinator()
  169. require.Nil(t, err)
  170. assert.Equal(t, &bootCoordinatorAddressConst, bootCoordinator)
  171. }
  172. func TestAuctionSetDonationAddress(t *testing.T) {
  173. newDonationAddress := governanceAddressConst
  174. _, err := auctionClientTest.AuctionSetDonationAddress(newDonationAddress)
  175. require.Nil(t, err)
  176. donationAddress, err := auctionClientTest.AuctionGetDonationAddress()
  177. require.Nil(t, err)
  178. assert.Equal(t, &newDonationAddress, donationAddress)
  179. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  180. require.Nil(t, err)
  181. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  182. require.Nil(t, err)
  183. assert.Equal(t, newDonationAddress, auctionEvents.NewDonationAddress[0].NewDonationAddress)
  184. _, err = auctionClientTest.AuctionSetDonationAddress(donationAddressConst)
  185. require.Nil(t, err)
  186. }
  187. func TestAuctionSetBootCoordinator(t *testing.T) {
  188. newBootCoordinator := governanceAddressConst
  189. bootCoordinatorURL := "https://boot.coordinator2.io"
  190. newBootCoordinatorURL := "https://boot.coordinator2.io"
  191. _, err := auctionClientTest.AuctionSetBootCoordinator(newBootCoordinator, newBootCoordinatorURL)
  192. require.Nil(t, err)
  193. bootCoordinator, err := auctionClientTest.AuctionGetBootCoordinator()
  194. require.Nil(t, err)
  195. assert.Equal(t, &newBootCoordinator, bootCoordinator)
  196. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  197. require.Nil(t, err)
  198. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  199. require.Nil(t, err)
  200. assert.Equal(t, newBootCoordinator, auctionEvents.NewBootCoordinator[0].NewBootCoordinator)
  201. assert.Equal(t, newBootCoordinatorURL, auctionEvents.NewBootCoordinator[0].NewBootCoordinatorURL)
  202. _, err = auctionClientTest.AuctionSetBootCoordinator(bootCoordinatorAddressConst,
  203. bootCoordinatorURL)
  204. require.Nil(t, err)
  205. }
  206. func TestAuctionGetSlotSet(t *testing.T) {
  207. slot := int64(10)
  208. slotSet, err := auctionClientTest.AuctionGetSlotSet(slot)
  209. require.Nil(t, err)
  210. assert.Equal(t, slotSet, big.NewInt(4))
  211. }
  212. func TestAuctionGetDefaultSlotSetBid(t *testing.T) {
  213. slotSet := uint8(3)
  214. minBid, err := auctionClientTest.AuctionGetDefaultSlotSetBid(slotSet)
  215. require.Nil(t, err)
  216. assert.Equal(t, minBid.String(), minBidStr)
  217. }
  218. func TestAuctionChangeDefaultSlotSetBid(t *testing.T) {
  219. slotSet := int64(3)
  220. set := uint8(3)
  221. newInitialMinBid := new(big.Int)
  222. newInitialMinBid.SetString("20000000000000000000", 10)
  223. _, err := auctionClientTest.AuctionChangeDefaultSlotSetBid(slotSet, newInitialMinBid)
  224. require.Nil(t, err)
  225. minBid, err := auctionClientTest.AuctionGetDefaultSlotSetBid(set)
  226. require.Nil(t, err)
  227. assert.Equal(t, minBid, newInitialMinBid)
  228. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  229. require.Nil(t, err)
  230. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  231. require.Nil(t, err)
  232. assert.Equal(t, slotSet, auctionEvents.NewDefaultSlotSetBid[0].SlotSet)
  233. assert.Equal(t, newInitialMinBid, auctionEvents.NewDefaultSlotSetBid[0].NewInitialMinBid)
  234. newMinBid := new(big.Int)
  235. newMinBid.SetString("10000000000000000000", 10)
  236. _, err = auctionClientTest.AuctionChangeDefaultSlotSetBid(slotSet, newMinBid)
  237. require.Nil(t, err)
  238. }
  239. func TestAuctionGetClaimableHEZ(t *testing.T) {
  240. bidderAddress := governanceAddressConst
  241. claimableHEZ, err := auctionClientTest.AuctionGetClaimableHEZ(bidderAddress)
  242. require.Nil(t, err)
  243. assert.Equal(t, claimableHEZ.Int64(), int64(0))
  244. }
  245. func TestAuctionRegisterCoordinator(t *testing.T) {
  246. forgerAddress := governanceAddressConst
  247. bidderAddress := governanceAddressConst
  248. _, err := auctionClientTest.AuctionSetCoordinator(forgerAddress, URL)
  249. require.Nil(t, err)
  250. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  251. require.Nil(t, err)
  252. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  253. require.Nil(t, err)
  254. assert.Equal(t, forgerAddress, auctionEvents.SetCoordinator[0].ForgerAddress)
  255. assert.Equal(t, bidderAddress, auctionEvents.SetCoordinator[0].BidderAddress)
  256. assert.Equal(t, URL, auctionEvents.SetCoordinator[0].CoordinatorURL)
  257. }
  258. func TestAuctionBid(t *testing.T) {
  259. currentSlot, err := auctionClientTest.AuctionGetCurrentSlotNumber()
  260. require.Nil(t, err)
  261. bidAmount := new(big.Int)
  262. bidAmount.SetString("12000000000000000000", 10)
  263. amount := new(big.Int)
  264. amount.SetString("12000000000000000000", 10)
  265. bidderAddress := governanceAddressConst
  266. _, err = auctionClientTest.AuctionBid(amount, currentSlot+4, bidAmount, deadline)
  267. require.Nil(t, err)
  268. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  269. require.Nil(t, err)
  270. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  271. require.Nil(t, err)
  272. assert.Equal(t, bidAmount, auctionEvents.NewBid[0].BidAmount)
  273. assert.Equal(t, bidderAddress, auctionEvents.NewBid[0].Bidder)
  274. assert.Equal(t, currentSlot+4, auctionEvents.NewBid[0].Slot)
  275. }
  276. func TestAuctionGetSlotNumber(t *testing.T) {
  277. slotConst := 4
  278. blockNum := int(blocksPerSlot)*slotConst + int(genesisBlock)
  279. slot, err := auctionClientTest.AuctionGetSlotNumber(int64(blockNum))
  280. require.Nil(t, err)
  281. assert.Equal(t, slot, int64(slotConst))
  282. }
  283. func TestAuctionCanForge(t *testing.T) {
  284. slotConst := 4
  285. blockNum := int(blocksPerSlot)*slotConst + int(genesisBlock)
  286. canForge, err := auctionClientTest.AuctionCanForge(governanceAddressConst, int64(blockNum))
  287. require.Nil(t, err)
  288. assert.Equal(t, canForge, true)
  289. }
  290. func TestAuctionMultiBid(t *testing.T) {
  291. currentSlot, err := auctionClientTest.AuctionGetCurrentSlotNumber()
  292. require.Nil(t, err)
  293. slotSet := [6]bool{true, false, true, false, true, false}
  294. maxBid := new(big.Int)
  295. maxBid.SetString("15000000000000000000", 10)
  296. minBid := new(big.Int)
  297. minBid.SetString("11000000000000000000", 10)
  298. budget := new(big.Int)
  299. budget.SetString("45200000000000000000", 10)
  300. bidderAddress := governanceAddressConst
  301. _, err = auctionClientTest.AuctionMultiBid(budget, currentSlot+4, currentSlot+10, slotSet,
  302. maxBid, minBid, deadline)
  303. require.Nil(t, err)
  304. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  305. require.Nil(t, err)
  306. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  307. require.Nil(t, err)
  308. assert.Equal(t, bidderAddress, auctionEvents.NewBid[0].Bidder)
  309. assert.Equal(t, currentSlot+4, auctionEvents.NewBid[0].Slot)
  310. assert.Equal(t, bidderAddress, auctionEvents.NewBid[1].Bidder)
  311. assert.Equal(t, currentSlot+6, auctionEvents.NewBid[1].Slot)
  312. assert.Equal(t, bidderAddress, auctionEvents.NewBid[2].Bidder)
  313. assert.Equal(t, currentSlot+8, auctionEvents.NewBid[2].Slot)
  314. assert.Equal(t, bidderAddress, auctionEvents.NewBid[3].Bidder)
  315. assert.Equal(t, currentSlot+10, auctionEvents.NewBid[3].Slot)
  316. }
  317. func TestAuctionGetClaimableHEZ2(t *testing.T) {
  318. bidderAddress := governanceAddressConst
  319. amount := new(big.Int)
  320. amount.SetString("11000000000000000000", 10)
  321. claimableHEZ, err := auctionClientTest.AuctionGetClaimableHEZ(bidderAddress)
  322. require.Nil(t, err)
  323. assert.Equal(t, claimableHEZ, amount)
  324. }
  325. func TestAuctionClaimHEZ(t *testing.T) {
  326. amount := new(big.Int)
  327. amount.SetString("11000000000000000000", 10)
  328. _, err := auctionClientTest.AuctionClaimHEZ()
  329. require.Nil(t, err)
  330. currentBlockNum, err := auctionClientTest.client.EthLastBlock()
  331. require.Nil(t, err)
  332. auctionEvents, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum, nil)
  333. require.Nil(t, err)
  334. assert.Equal(t, amount, auctionEvents.HEZClaimed[0].Amount)
  335. assert.Equal(t, governanceAddressConst, auctionEvents.HEZClaimed[0].Owner)
  336. }
  337. func TestAuctionForge(t *testing.T) {
  338. auctionClientTestHermez, err := NewAuctionClient(ethereumClientHermez,
  339. auctionTestAddressConst, tokenHEZ)
  340. require.Nil(t, err)
  341. slotConst := 4
  342. blockNum := int64(int(blocksPerSlot)*slotConst + int(genesisBlock))
  343. currentBlockNum, err := auctionClientTestHermez.client.EthLastBlock()
  344. require.Nil(t, err)
  345. blocksToAdd := blockNum - currentBlockNum
  346. addBlocks(blocksToAdd, ethClientDialURL)
  347. currentBlockNum, err = auctionClientTestHermez.client.EthLastBlock()
  348. require.Nil(t, err)
  349. assert.Equal(t, currentBlockNum, blockNum)
  350. _, err = auctionClientTestHermez.AuctionForge(governanceAddressConst)
  351. require.Nil(t, err)
  352. }