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.

108 lines
3.2 KiB

  1. package eth
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/ethereum/go-ethereum/common"
  6. "github.com/ethereum/go-ethereum/ethclient"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. )
  10. const slotDeadlineConst = uint8(20)
  11. const openAuctionSlotsConst = 4320
  12. const closedAuctionSlotsConst = 2
  13. const outbiddingConst = 10
  14. const currentSlotConst = 0
  15. var allocationRatioConst [3]uint8 = [3]uint8{40, 40, 20}
  16. var auctionClient *AuctionClient
  17. var donationAddressConstStr = os.Getenv("DONATION_ADDRESS")
  18. var bootCoordinatorConstStr = os.Getenv("BOOT_COORDINATOR_ADDRESS")
  19. var integration = os.Getenv("INTEGRATION")
  20. var ehtClientDialURL = os.Getenv("ETHCLIENT_DIAL_URL")
  21. var auctionAddressStr = os.Getenv("AUCTION_ADDRESS")
  22. func TestNewAction(t *testing.T) {
  23. if integration != "" {
  24. // Init eth client
  25. ethClient, err := ethclient.Dial(ehtClientDialURL)
  26. require.Nil(t, err)
  27. ethereumClient := NewEthereumClient(ethClient, nil, nil, nil)
  28. auctionAddress := common.HexToAddress(auctionAddressStr)
  29. auctionClient = NewAuctionClient(ethereumClient, auctionAddress)
  30. }
  31. }
  32. func TestAuctionGetSlotDeadline(t *testing.T) {
  33. if auctionClient != nil {
  34. slotDeadline, err := auctionClient.AuctionGetSlotDeadline()
  35. require.Nil(t, err)
  36. assert.Equal(t, slotDeadlineConst, slotDeadline)
  37. }
  38. }
  39. func TestAuctionGetOpenAuctionSlots(t *testing.T) {
  40. if auctionClient != nil {
  41. openAuctionSlots, err := auctionClient.AuctionGetOpenAuctionSlots()
  42. require.Nil(t, err)
  43. openAuctionSlotsInt := int(openAuctionSlots)
  44. assert.Equal(t, openAuctionSlotsConst, openAuctionSlotsInt)
  45. }
  46. }
  47. func TestAuctionGetClosedAuctionSlots(t *testing.T) {
  48. if auctionClient != nil {
  49. closedAuctionSlots, err := auctionClient.AuctionGetClosedAuctionSlots()
  50. require.Nil(t, err)
  51. closedAuctionSlotsInt := int(closedAuctionSlots)
  52. assert.Equal(t, closedAuctionSlotsConst, closedAuctionSlotsInt)
  53. }
  54. }
  55. func TestAuctionGetOutbidding(t *testing.T) {
  56. if auctionClient != nil {
  57. outbidding, err := auctionClient.AuctionGetOutbidding()
  58. require.Nil(t, err)
  59. outbiddingInt := int(outbidding)
  60. assert.Equal(t, outbiddingConst, outbiddingInt)
  61. }
  62. }
  63. func TestAuctionGetAllocationRatio(t *testing.T) {
  64. if auctionClient != nil {
  65. allocationRatio, err := auctionClient.AuctionGetAllocationRatio()
  66. require.Nil(t, err)
  67. assert.Equal(t, allocationRatioConst, allocationRatio)
  68. }
  69. }
  70. func TestAuctionGetDonationAddress(t *testing.T) {
  71. if auctionClient != nil {
  72. donationAddress, err := auctionClient.AuctionGetDonationAddress()
  73. require.Nil(t, err)
  74. donationAddressConst := common.HexToAddress(donationAddressConstStr)
  75. assert.Equal(t, &donationAddressConst, donationAddress)
  76. }
  77. }
  78. func TestAuctionGetBootCoordinator(t *testing.T) {
  79. if auctionClient != nil {
  80. bootCoordinator, err := auctionClient.AuctionGetBootCoordinator()
  81. require.Nil(t, err)
  82. bootCoordinatorConst := common.HexToAddress(bootCoordinatorConstStr)
  83. assert.Equal(t, &bootCoordinatorConst, bootCoordinator)
  84. }
  85. }
  86. func TestAuctionGetCurrentSlotNumber(t *testing.T) {
  87. if auctionClient != nil {
  88. currentSlot, err := auctionClient.AuctionGetCurrentSlotNumber()
  89. require.Nil(t, err)
  90. currentSlotInt := int(currentSlot)
  91. assert.Equal(t, currentSlotConst, currentSlotInt)
  92. }
  93. }