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.

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