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.

162 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" //nolint:gosec
  35. tokenERC20AddressConst = ethCommon.HexToAddress(tokenERC20AddressStr)
  36. tokenHEZAddressConst = tokenERC777AddressConst
  37. hermezRollupAddressStr = "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0"
  38. hermezRollupAddressConst = ethCommon.HexToAddress(hermezRollupAddressStr)
  39. wdelayerAddressStr = "0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe"
  40. wdelayerAddressConst = ethCommon.HexToAddress(wdelayerAddressStr)
  41. wdelayerTestAddressStr = "0x52d3b94181f8654db2530b0fEe1B19173f519C52"
  42. wdelayerTestAddressConst = ethCommon.HexToAddress(wdelayerTestAddressStr)
  43. safetyAddressStr = "0xE5904695748fe4A84b40b3fc79De2277660BD1D3"
  44. safetyAddressConst = ethCommon.HexToAddress(safetyAddressStr)
  45. )
  46. // Ethereum Accounts
  47. var (
  48. hermezGovernanceDAOAddressSK = "2a8aede924268f84156a00761de73998dac7bf703408754b776ff3f873bcec60"
  49. hermezGovernanceDAOAddressStr = "0x84Fae3d3Cba24A97817b2a18c2421d462dbBCe9f"
  50. hermezGovernanceDAOAddressConst = ethCommon.HexToAddress(hermezGovernanceDAOAddressStr)
  51. whiteHackGroupAddressSK = "8b24fd94f1ce869d81a34b95351e7f97b2cd88a891d5c00abc33d0ec9501902e"
  52. whiteHackGroupAddressStr = "0xfa3BdC8709226Da0dA13A4d904c8b66f16c3c8BA"
  53. whiteHackGroupAddressConst = ethCommon.HexToAddress(whiteHackGroupAddressStr)
  54. hermezKeeperAddressSK = "7f307c41137d1ed409f0a7b028f6c7596f12734b1d289b58099b99d60a96efff"
  55. hermezKeeperAddressStr = "0xFbC51a9582D031f2ceaaD3959256596C5D3a5468"
  56. hermezKeeperAddressConst = ethCommon.HexToAddress(hermezKeeperAddressStr)
  57. governanceAddressSK = "d49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb"
  58. governanceAddressStr = "0xead9c93b79ae7c1591b1fb5323bd777e86e150d4"
  59. governanceAddressConst = ethCommon.HexToAddress(governanceAddressStr)
  60. auxAddressSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29089"
  61. auxAddressStr = "0x3d91185a02774C70287F6c74Dd26d13DFB58ff16"
  62. auxAddressConst = ethCommon.HexToAddress(auxAddressStr)
  63. hermezRollupTestSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29088"
  64. hermezRollupTestAddressStr = "0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0"
  65. hermezRollupAddressTestConst = ethCommon.HexToAddress(hermezRollupTestAddressStr)
  66. )
  67. var (
  68. accountGov *accounts.Account
  69. accountKep *accounts.Account
  70. accountWhite *accounts.Account
  71. accountGovDAO *accounts.Account
  72. accountAux *accounts.Account
  73. accountHermez *accounts.Account
  74. ks *keystore.KeyStore
  75. ethClient *ethclient.Client
  76. ethereumClientWhite *EthereumClient
  77. ethereumClientKep *EthereumClient
  78. ethereumClientGovDAO *EthereumClient
  79. ethereumClientAux *EthereumClient
  80. ethereumClientHermez *EthereumClient
  81. )
  82. func addKey(ks *keystore.KeyStore, skHex string) *accounts.Account {
  83. key, err := crypto.HexToECDSA(skHex)
  84. if err != nil {
  85. panic(err)
  86. }
  87. account, err := ks.ImportECDSA(key, password)
  88. if err != nil {
  89. panic(err)
  90. }
  91. err = ks.Unlock(account, password)
  92. if err != nil {
  93. panic(err)
  94. }
  95. return &account
  96. }
  97. func TestMain(m *testing.M) {
  98. exitVal := 0
  99. if os.Getenv("INTEGRATION") != "" {
  100. dir, err := ioutil.TempDir("", "tmpks")
  101. if err != nil {
  102. panic(err)
  103. }
  104. ks = keystore.NewKeyStore(dir, keystore.LightScryptN, keystore.LightScryptP)
  105. // Load ethereum accounts from private keys
  106. accountGov = addKey(ks, governanceAddressSK)
  107. accountKep = addKey(ks, hermezKeeperAddressSK)
  108. accountWhite = addKey(ks, whiteHackGroupAddressSK)
  109. accountGovDAO = addKey(ks, hermezGovernanceDAOAddressSK)
  110. accountAux = addKey(ks, auxAddressSK)
  111. accountHermez = addKey(ks, hermezRollupTestSK)
  112. ethClient, err = ethclient.Dial(ethClientDialURL)
  113. if err != nil {
  114. panic(err)
  115. }
  116. // Controllable Governance Address
  117. ethereumClientGov := NewEthereumClient(ethClient, accountGov, ks, nil)
  118. auctionClientTest, err = NewAuctionClient(ethereumClientGov, auctionTestAddressConst, tokenHEZAddressConst)
  119. if err != nil {
  120. panic(err)
  121. }
  122. rollupClient, err = NewRollupClient(ethereumClientGov, hermezRollupAddressConst)
  123. if err != nil {
  124. panic(err)
  125. }
  126. wdelayerClient, err = NewWDelayerClient(ethereumClientGov, wdelayerAddressConst)
  127. if err != nil {
  128. panic(err)
  129. }
  130. wdelayerClientTest, err = NewWDelayerClient(ethereumClientGov, wdelayerTestAddressConst)
  131. if err != nil {
  132. panic(err)
  133. }
  134. ethereumClientKep = NewEthereumClient(ethClient, accountKep, ks, nil)
  135. ethereumClientWhite = NewEthereumClient(ethClient, accountWhite, ks, nil)
  136. ethereumClientGovDAO = NewEthereumClient(ethClient, accountGovDAO, ks, nil)
  137. ethereumClientAux = NewEthereumClient(ethClient, accountAux, ks, nil)
  138. ethereumClientHermez = NewEthereumClient(ethClient, accountHermez, ks, nil)
  139. exitVal = m.Run()
  140. }
  141. os.Exit(exitVal)
  142. }