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.

161 lines
6.3 KiB

  1. package eth
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "testing"
  6. "github.com/ethereum/go-ethereum/accounts"
  7. "github.com/ethereum/go-ethereum/accounts/keystore"
  8. ethCommon "github.com/ethereum/go-ethereum/common"
  9. "github.com/ethereum/go-ethereum/crypto"
  10. "github.com/ethereum/go-ethereum/ethclient"
  11. )
  12. /*var donationAddressStr = os.Getenv("DONATION_ADDRESS")
  13. var bootCoordinatorStr = os.Getenv("BOOT_COORDINATOR_ADDRESS")
  14. var auctionAddressStr = os.Getenv("AUCTION_ADDRESS")
  15. var tokenHezStr = os.Getenv("TOKEN_ADDRESS")
  16. var hermezStr = os.Getenv("HERMEZ_ADDRESS")
  17. var governanceAddressStr = os.Getenv("GOV_ADDRESS")
  18. var governancePrivateKey = os.Getenv("GOV_PK")
  19. var ethClientDialURL = os.Getenv("ETHCLIENT_DIAL_URL")*/
  20. var ethClientDialURL = "http://localhost:8545"
  21. var password = "pass"
  22. // Smart Contract Addresses
  23. var (
  24. auctionAddressStr = "0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e"
  25. auctionAddressConst = ethCommon.HexToAddress(auctionAddressStr)
  26. auctionTestAddressStr = "0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160"
  27. auctionTestAddressConst = ethCommon.HexToAddress(auctionTestAddressStr)
  28. donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd"
  29. donationAddressConst = ethCommon.HexToAddress(donationAddressStr)
  30. bootCoordinatorAddressStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6"
  31. bootCoordinatorAddressConst = ethCommon.HexToAddress(bootCoordinatorAddressStr)
  32. tokenERC777AddressStr = "0xf784709d2317D872237C4bC22f867d1BAe2913AB" //nolint:gosec
  33. tokenERC777AddressConst = ethCommon.HexToAddress(tokenERC777AddressStr)
  34. tokenERC20AddressStr = "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5"
  35. tokenERC20AddressConst = ethCommon.HexToAddress(tokenERC20AddressStr)
  36. hermezRollupAddressStr = "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0"
  37. hermezRollupAddressConst = ethCommon.HexToAddress(hermezRollupAddressStr)
  38. wdelayerAddressStr = "0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe"
  39. wdelayerAddressConst = ethCommon.HexToAddress(wdelayerAddressStr)
  40. wdelayerTestAddressStr = "0x52d3b94181f8654db2530b0fEe1B19173f519C52"
  41. wdelayerTestAddressConst = ethCommon.HexToAddress(wdelayerTestAddressStr)
  42. safetyAddressStr = "0xE5904695748fe4A84b40b3fc79De2277660BD1D3"
  43. safetyAddressConst = ethCommon.HexToAddress(safetyAddressStr)
  44. )
  45. // Ethereum Accounts
  46. var (
  47. hermezGovernanceDAOAddressSK = "2a8aede924268f84156a00761de73998dac7bf703408754b776ff3f873bcec60"
  48. hermezGovernanceDAOAddressStr = "0x84Fae3d3Cba24A97817b2a18c2421d462dbBCe9f"
  49. hermezGovernanceDAOAddressConst = ethCommon.HexToAddress(hermezGovernanceDAOAddressStr)
  50. whiteHackGroupAddressSK = "8b24fd94f1ce869d81a34b95351e7f97b2cd88a891d5c00abc33d0ec9501902e"
  51. whiteHackGroupAddressStr = "0xfa3BdC8709226Da0dA13A4d904c8b66f16c3c8BA"
  52. whiteHackGroupAddressConst = ethCommon.HexToAddress(whiteHackGroupAddressStr)
  53. hermezKeeperAddressSK = "7f307c41137d1ed409f0a7b028f6c7596f12734b1d289b58099b99d60a96efff"
  54. hermezKeeperAddressStr = "0xFbC51a9582D031f2ceaaD3959256596C5D3a5468"
  55. hermezKeeperAddressConst = ethCommon.HexToAddress(hermezKeeperAddressStr)
  56. governanceAddressSK = "d49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb"
  57. governanceAddressStr = "0xead9c93b79ae7c1591b1fb5323bd777e86e150d4"
  58. governanceAddressConst = ethCommon.HexToAddress(governanceAddressStr)
  59. auxAddressSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29089"
  60. auxAddressStr = "0x3d91185a02774C70287F6c74Dd26d13DFB58ff16"
  61. auxAddressConst = ethCommon.HexToAddress(auxAddressStr)
  62. hermezRollupTestSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29088"
  63. hermezRollupTestAddressStr = "0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0"
  64. hermezRollupAddressTestConst = ethCommon.HexToAddress(hermezRollupTestAddressStr)
  65. )
  66. var (
  67. accountGov *accounts.Account
  68. accountKep *accounts.Account
  69. accountWhite *accounts.Account
  70. accountGovDAO *accounts.Account
  71. accountAux *accounts.Account
  72. accountHermez *accounts.Account
  73. ks *keystore.KeyStore
  74. ethClient *ethclient.Client
  75. ethereumClientWhite *EthereumClient
  76. ethereumClientKep *EthereumClient
  77. ethereumClientGovDAO *EthereumClient
  78. ethereumClientAux *EthereumClient
  79. ethereumClientHermez *EthereumClient
  80. )
  81. func addKey(ks *keystore.KeyStore, skHex string) *accounts.Account {
  82. key, err := crypto.HexToECDSA(skHex)
  83. if err != nil {
  84. panic(err)
  85. }
  86. account, err := ks.ImportECDSA(key, password)
  87. if err != nil {
  88. panic(err)
  89. }
  90. err = ks.Unlock(account, password)
  91. if err != nil {
  92. panic(err)
  93. }
  94. return &account
  95. }
  96. func TestMain(m *testing.M) {
  97. exitVal := 0
  98. if os.Getenv("INTEGRATION") != "" {
  99. dir, err := ioutil.TempDir("", "tmpks")
  100. if err != nil {
  101. panic(err)
  102. }
  103. ks = keystore.NewKeyStore(dir, keystore.LightScryptN, keystore.LightScryptP)
  104. // Load ethereum accounts from private keys
  105. accountGov = addKey(ks, governanceAddressSK)
  106. accountKep = addKey(ks, hermezKeeperAddressSK)
  107. accountWhite = addKey(ks, whiteHackGroupAddressSK)
  108. accountGovDAO = addKey(ks, hermezGovernanceDAOAddressSK)
  109. accountAux = addKey(ks, auxAddressSK)
  110. accountHermez = addKey(ks, hermezRollupTestSK)
  111. ethClient, err = ethclient.Dial(ethClientDialURL)
  112. if err != nil {
  113. panic(err)
  114. }
  115. // Controllable Governance Address
  116. ethereumClientGov := NewEthereumClient(ethClient, accountGov, ks, nil)
  117. auctionClientTest, err = NewAuctionClient(ethereumClientGov, auctionTestAddressConst, tokenERC777AddressConst)
  118. if err != nil {
  119. panic(err)
  120. }
  121. rollupClient, err = NewRollupClient(ethereumClientGov, hermezRollupAddressConst)
  122. if err != nil {
  123. panic(err)
  124. }
  125. wdelayerClient, err = NewWDelayerClient(ethereumClientGov, wdelayerAddressConst)
  126. if err != nil {
  127. panic(err)
  128. }
  129. wdelayerClientTest, err = NewWDelayerClient(ethereumClientGov, wdelayerTestAddressConst)
  130. if err != nil {
  131. panic(err)
  132. }
  133. ethereumClientKep = NewEthereumClient(ethClient, accountKep, ks, nil)
  134. ethereumClientWhite = NewEthereumClient(ethClient, accountWhite, ks, nil)
  135. ethereumClientGovDAO = NewEthereumClient(ethClient, accountGovDAO, ks, nil)
  136. ethereumClientAux = NewEthereumClient(ethClient, accountAux, ks, nil)
  137. ethereumClientHermez = NewEthereumClient(ethClient, accountHermez, ks, nil)
  138. exitVal = m.Run()
  139. }
  140. os.Exit(exitVal)
  141. }