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.

148 lines
5.6 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 = "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5"
  25. // wdelayerAddressStr = "0x1A1FEe7EeD918BD762173e4dc5EfDB8a78C924A8"
  26. auctionAddressStr = "0x8B5B7a6055E54a36fF574bbE40cf2eA68d5554b3"
  27. auctionAddressConst = ethCommon.HexToAddress(auctionAddressStr)
  28. donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd"
  29. donationAddressConst = ethCommon.HexToAddress(donationAddressStr)
  30. bootCoordinatorAddressStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6"
  31. bootCoordinatorAddressConst = ethCommon.HexToAddress(bootCoordinatorAddressStr)
  32. tokenHezAddressStr = "0xf4e77E5Da47AC3125140c470c71cBca77B5c638c" //nolint:gosec
  33. tokenHezAddressConst = ethCommon.HexToAddress(tokenHezAddressStr)
  34. hermezRollupAddressStr = "0xc4905364b78a742ccce7B890A89514061E47068D"
  35. hermezRollupAddressConst = ethCommon.HexToAddress(hermezRollupAddressStr)
  36. wdelayerAddressStr = "0x20Ce94F404343aD2752A2D01b43fa407db9E0D00"
  37. wdelayerAddressConst = ethCommon.HexToAddress(wdelayerAddressStr)
  38. )
  39. // Ethereum Accounts
  40. var (
  41. hermezGovernanceDAOAddressSK = "2a8aede924268f84156a00761de73998dac7bf703408754b776ff3f873bcec60"
  42. hermezGovernanceDAOAddressStr = "0x84Fae3d3Cba24A97817b2a18c2421d462dbBCe9f"
  43. hermezGovernanceDAOAddressConst = ethCommon.HexToAddress(hermezGovernanceDAOAddressStr)
  44. whiteHackGroupAddressSK = "8b24fd94f1ce869d81a34b95351e7f97b2cd88a891d5c00abc33d0ec9501902e"
  45. whiteHackGroupAddressStr = "0xfa3BdC8709226Da0dA13A4d904c8b66f16c3c8BA"
  46. whiteHackGroupAddressConst = ethCommon.HexToAddress(whiteHackGroupAddressStr)
  47. hermezKeeperAddressSK = "7f307c41137d1ed409f0a7b028f6c7596f12734b1d289b58099b99d60a96efff"
  48. hermezKeeperAddressStr = "0xFbC51a9582D031f2ceaaD3959256596C5D3a5468"
  49. hermezKeeperAddressConst = ethCommon.HexToAddress(hermezKeeperAddressStr)
  50. governanceAddressSK = "d49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb"
  51. governanceAddressStr = "0xead9c93b79ae7c1591b1fb5323bd777e86e150d4"
  52. governanceAddressConst = ethCommon.HexToAddress(governanceAddressStr)
  53. auxAddressSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29089"
  54. auxAddressStr = "0x3d91185a02774C70287F6c74Dd26d13DFB58ff16"
  55. auxAddressConst = ethCommon.HexToAddress(auxAddressStr)
  56. hermezRollupTestSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29088"
  57. hermezRollupTestAddressStr = "0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0"
  58. hermezRollupAddressTestConst = ethCommon.HexToAddress(hermezRollupTestAddressStr)
  59. )
  60. var (
  61. accountGov *accounts.Account
  62. accountKep *accounts.Account
  63. accountWhite *accounts.Account
  64. accountGovDAO *accounts.Account
  65. accountAux *accounts.Account
  66. accountHermez *accounts.Account
  67. ks *keystore.KeyStore
  68. ethClient *ethclient.Client
  69. ethereumClientWhite *EthereumClient
  70. ethereumClientKep *EthereumClient
  71. ethereumClientGovDAO *EthereumClient
  72. ethereumClientAux *EthereumClient
  73. ethereumClientHermez *EthereumClient
  74. )
  75. func addKey(ks *keystore.KeyStore, skHex string) *accounts.Account {
  76. key, err := crypto.HexToECDSA(skHex)
  77. if err != nil {
  78. panic(err)
  79. }
  80. account, err := ks.ImportECDSA(key, password)
  81. if err != nil {
  82. panic(err)
  83. }
  84. err = ks.Unlock(account, password)
  85. if err != nil {
  86. panic(err)
  87. }
  88. return &account
  89. }
  90. func TestMain(m *testing.M) {
  91. exitVal := 0
  92. if os.Getenv("INTEGRATION") != "" {
  93. dir, err := ioutil.TempDir("", "tmpks")
  94. if err != nil {
  95. panic(err)
  96. }
  97. ks = keystore.NewKeyStore(dir, keystore.LightScryptN, keystore.LightScryptP)
  98. // Load ethereum accounts from private keys
  99. accountGov = addKey(ks, governanceAddressSK)
  100. accountKep = addKey(ks, hermezKeeperAddressSK)
  101. accountWhite = addKey(ks, whiteHackGroupAddressSK)
  102. accountGovDAO = addKey(ks, hermezGovernanceDAOAddressSK)
  103. accountAux = addKey(ks, auxAddressSK)
  104. accountHermez = addKey(ks, hermezRollupTestSK)
  105. ethClient, err = ethclient.Dial(ethClientDialURL)
  106. if err != nil {
  107. panic(err)
  108. }
  109. // Controllable Governance Address
  110. ethereumClientGov := NewEthereumClient(ethClient, accountGov, ks, nil)
  111. auctionClient, err = NewAuctionClient(ethereumClientGov, auctionAddressConst, tokenHezAddressConst)
  112. if err != nil {
  113. panic(err)
  114. }
  115. rollupClient = NewRollupClient(ethereumClientGov, hermezRollupAddressConst)
  116. wdelayerClient, err = NewWDelayerClient(ethereumClientGov, wdelayerAddressConst)
  117. if err != nil {
  118. panic(err)
  119. }
  120. ethereumClientKep = NewEthereumClient(ethClient, accountKep, ks, nil)
  121. ethereumClientWhite = NewEthereumClient(ethClient, accountWhite, ks, nil)
  122. ethereumClientGovDAO = NewEthereumClient(ethClient, accountGovDAO, ks, nil)
  123. ethereumClientAux = NewEthereumClient(ethClient, accountAux, ks, nil)
  124. ethereumClientHermez = NewEthereumClient(ethClient, accountHermez, ks, nil)
  125. exitVal = m.Run()
  126. }
  127. os.Exit(exitVal)
  128. }