mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-08 03:46:52 +01:00
Reorganize smart contract types, udate eth tests, etc.
- Move smart contract constants and structs for variables to
common/{ethrollup.go, ethauction.go, ethwdelayer.go}:
- This removes repeated code of the structs for variables
- Allows reusing the constants and variables from all modules without
import cycles
- Remove unused common/scvars.go
- In common.BlockData, split data from each smart contract into a sepparate
field (Rollup, Auction, WDelayer). This affects the structures that til uses
as output, and HistoryDB in the AddBlockSCData.
- In Synchronizer:
- Pass starting block of each smart contract as config, instead of
incorrectly using the genesis block found in the acution constant (which
has a very different meaning)
- Use variable structs from common instead of an internal copy
- Synchronize more stuff (resolve some TODOs)
- Fix some issues found after initial testing with ganache
- In eth:
- In auction.go: Add method to get constants
- Update README to use ganache instead of buidlerevm as local blockchain
for testing
- Update env variables and test vectors to pass the tests with the
deployment in the ganache testnet.
- Use ethereum keys derived from paths (hdwallet) in testing to avoid
hardcoding private keys and generate the same keys from a mnemonic used
in the ganache tesnet.
This commit is contained in:
157
eth/main_test.go
157
eth/main_test.go
@@ -3,6 +3,7 @@ package eth
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/big"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -11,9 +12,9 @@ import (
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/joho/godotenv"
|
||||
hdwallet "github.com/miguelmota/go-ethereum-hdwallet"
|
||||
)
|
||||
|
||||
var errEnvVar = fmt.Errorf("Some environment variable is missing")
|
||||
@@ -22,8 +23,31 @@ var (
|
||||
ethClientDialURL = "http://localhost:8545"
|
||||
password = "pass"
|
||||
deadline, _ = new(big.Int).SetString("ffffffffffffffffffffffffffffffff", 16)
|
||||
mnemonic = "explain tackle mirror kit van hammer degree position ginger unfair soup bonus"
|
||||
)
|
||||
|
||||
func genAcc(w *hdwallet.Wallet, ks *keystore.KeyStore, i int) (*accounts.Account, ethCommon.Address) {
|
||||
path := hdwallet.MustParseDerivationPath(fmt.Sprintf("m/44'/60'/0'/0/%d", i))
|
||||
account, err := w.Derive(path, false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
key, err := w.PrivateKey(account)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, err = ks.ImportECDSA(key, password)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := ks.Unlock(account, password); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return &account, account.Address
|
||||
}
|
||||
|
||||
// Smart Contract Addresses
|
||||
var (
|
||||
genesisBlock int64
|
||||
@@ -35,53 +59,41 @@ var (
|
||||
wdelayerTestAddressConst ethCommon.Address
|
||||
tokenHEZ TokenConfig
|
||||
|
||||
donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd"
|
||||
donationAddressConst = ethCommon.HexToAddress(donationAddressStr)
|
||||
bootCoordinatorAddressStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6"
|
||||
bootCoordinatorAddressConst = ethCommon.HexToAddress(bootCoordinatorAddressStr)
|
||||
safetyAddressStr = "0xE5904695748fe4A84b40b3fc79De2277660BD1D3"
|
||||
safetyAddressConst = ethCommon.HexToAddress(safetyAddressStr)
|
||||
donationAccount *accounts.Account
|
||||
donationAddressConst ethCommon.Address
|
||||
|
||||
bootCoordinatorAccount *accounts.Account
|
||||
bootCoordinatorAddressConst ethCommon.Address
|
||||
|
||||
safetyAccount *accounts.Account
|
||||
safetyAddressConst ethCommon.Address
|
||||
)
|
||||
|
||||
// Ethereum Accounts
|
||||
var (
|
||||
hermezGovernanceDAOAddressSK = "2a8aede924268f84156a00761de73998dac7bf703408754b776ff3f873bcec60"
|
||||
hermezGovernanceDAOAddressStr = "0x84Fae3d3Cba24A97817b2a18c2421d462dbBCe9f"
|
||||
hermezGovernanceDAOAddressConst = ethCommon.HexToAddress(hermezGovernanceDAOAddressStr)
|
||||
hermezGovernanceDAOAccount *accounts.Account
|
||||
hermezGovernanceDAOAddressConst ethCommon.Address
|
||||
|
||||
whiteHackGroupAddressSK = "8b24fd94f1ce869d81a34b95351e7f97b2cd88a891d5c00abc33d0ec9501902e"
|
||||
whiteHackGroupAddressStr = "0xfa3BdC8709226Da0dA13A4d904c8b66f16c3c8BA"
|
||||
whiteHackGroupAddressConst = ethCommon.HexToAddress(whiteHackGroupAddressStr)
|
||||
whiteHackGroupAccount *accounts.Account
|
||||
whiteHackGroupAddressConst ethCommon.Address
|
||||
|
||||
hermezKeeperAddressSK = "7f307c41137d1ed409f0a7b028f6c7596f12734b1d289b58099b99d60a96efff"
|
||||
hermezKeeperAddressStr = "0xFbC51a9582D031f2ceaaD3959256596C5D3a5468"
|
||||
hermezKeeperAddressConst = ethCommon.HexToAddress(hermezKeeperAddressStr)
|
||||
hermezKeeperAccount *accounts.Account
|
||||
hermezKeeperAddressConst ethCommon.Address
|
||||
|
||||
governanceAddressSK = "d49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb"
|
||||
governanceAddressStr = "0xead9c93b79ae7c1591b1fb5323bd777e86e150d4"
|
||||
governanceAddressConst = ethCommon.HexToAddress(governanceAddressStr)
|
||||
governanceAccount *accounts.Account
|
||||
governanceAddressConst ethCommon.Address
|
||||
|
||||
auxAddressSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29089"
|
||||
auxAddressStr = "0x3d91185a02774C70287F6c74Dd26d13DFB58ff16"
|
||||
auxAddressConst = ethCommon.HexToAddress(auxAddressStr)
|
||||
auxAccount *accounts.Account
|
||||
auxAddressConst ethCommon.Address
|
||||
|
||||
aux2AddressSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29087"
|
||||
// aux2AddressStr = "0x532792b73c0c6e7565912e7039c59986f7e1dd1f"
|
||||
// aux2AddressConst = ethCommon.HexToAddress(aux2AddressStr)
|
||||
aux2Account *accounts.Account
|
||||
aux2AddressConst ethCommon.Address
|
||||
|
||||
hermezRollupTestSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29088"
|
||||
hermezRollupTestAddressStr = "0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0"
|
||||
hermezRollupAddressTestConst = ethCommon.HexToAddress(hermezRollupTestAddressStr)
|
||||
hermezRollupTestAccount *accounts.Account
|
||||
hermezRollupTestAddressConst ethCommon.Address
|
||||
)
|
||||
|
||||
var (
|
||||
accountGov *accounts.Account
|
||||
accountKep *accounts.Account
|
||||
accountWhite *accounts.Account
|
||||
accountGovDAO *accounts.Account
|
||||
accountAux *accounts.Account
|
||||
accountAux2 *accounts.Account
|
||||
accountHermez *accounts.Account
|
||||
ks *keystore.KeyStore
|
||||
ethClient *ethclient.Client
|
||||
ethereumClientWhite *EthereumClient
|
||||
@@ -92,22 +104,6 @@ var (
|
||||
ethereumClientHermez *EthereumClient
|
||||
)
|
||||
|
||||
func addKey(ks *keystore.KeyStore, skHex string) *accounts.Account {
|
||||
key, err := crypto.HexToECDSA(skHex)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
account, err := ks.ImportECDSA(key, password)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = ks.Unlock(account, password)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &account
|
||||
}
|
||||
|
||||
func getEnvVariables() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
@@ -124,10 +120,10 @@ func getEnvVariables() {
|
||||
genesisBlockEnv := os.Getenv("GENESIS_BLOCK")
|
||||
genesisBlock, err = strconv.ParseInt(genesisBlockEnv, 10, 64)
|
||||
if err != nil {
|
||||
panic(errEnvVar)
|
||||
log.Fatal(errEnvVar)
|
||||
}
|
||||
if auctionAddressStr == "" || auctionTestAddressStr == "" || tokenHEZAddressStr == "" || hermezRollupAddressStr == "" || wdelayerAddressStr == "" || wdelayerTestAddressStr == "" || genesisBlockEnv == "" {
|
||||
panic(errEnvVar)
|
||||
log.Fatal(errEnvVar)
|
||||
}
|
||||
|
||||
auctionAddressConst = ethCommon.HexToAddress(auctionAddressStr)
|
||||
@@ -149,58 +145,67 @@ func TestMain(m *testing.M) {
|
||||
getEnvVariables()
|
||||
dir, err := ioutil.TempDir("", "tmpks")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := os.RemoveAll(dir); err != nil {
|
||||
panic(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
ks = keystore.NewKeyStore(dir, keystore.LightScryptN, keystore.LightScryptP)
|
||||
|
||||
// Load ethereum accounts from private keys
|
||||
accountGov = addKey(ks, governanceAddressSK)
|
||||
accountKep = addKey(ks, hermezKeeperAddressSK)
|
||||
accountWhite = addKey(ks, whiteHackGroupAddressSK)
|
||||
accountGovDAO = addKey(ks, hermezGovernanceDAOAddressSK)
|
||||
accountAux = addKey(ks, auxAddressSK)
|
||||
accountAux2 = addKey(ks, aux2AddressSK)
|
||||
accountHermez = addKey(ks, hermezRollupTestSK)
|
||||
w, err := hdwallet.NewFromMnemonic(mnemonic)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Create ethereum accounts from mnemonic and load private keys
|
||||
// into the keystore
|
||||
bootCoordinatorAccount, bootCoordinatorAddressConst = genAcc(w, ks, 0)
|
||||
governanceAccount, governanceAddressConst = genAcc(w, ks, 1)
|
||||
safetyAccount, safetyAddressConst = genAcc(w, ks, 2)
|
||||
hermezKeeperAccount, hermezKeeperAddressConst = genAcc(w, ks, 6)
|
||||
hermezGovernanceDAOAccount, hermezGovernanceDAOAddressConst = genAcc(w, ks, 7)
|
||||
whiteHackGroupAccount, whiteHackGroupAddressConst = genAcc(w, ks, 8)
|
||||
donationAccount, donationAddressConst = genAcc(w, ks, 9)
|
||||
aux2Account, aux2AddressConst = genAcc(w, ks, 11)
|
||||
hermezRollupTestAccount, hermezRollupTestAddressConst = genAcc(w, ks, 12)
|
||||
auxAccount, auxAddressConst = genAcc(w, ks, 13)
|
||||
|
||||
ethClient, err = ethclient.Dial(ethClientDialURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Controllable Governance Address
|
||||
ethereumClientGov := NewEthereumClient(ethClient, accountGov, ks, nil)
|
||||
ethereumClientGov := NewEthereumClient(ethClient, governanceAccount, ks, nil)
|
||||
auctionClient, err = NewAuctionClient(ethereumClientGov, auctionAddressConst, tokenHEZ)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
auctionClientTest, err = NewAuctionClient(ethereumClientGov, auctionTestAddressConst, tokenHEZ)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
rollupClient, err = NewRollupClient(ethereumClientGov, hermezRollupAddressConst, tokenHEZ)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
wdelayerClient, err = NewWDelayerClient(ethereumClientGov, wdelayerAddressConst)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
wdelayerClientTest, err = NewWDelayerClient(ethereumClientGov, wdelayerTestAddressConst)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ethereumClientKep = NewEthereumClient(ethClient, accountKep, ks, nil)
|
||||
ethereumClientWhite = NewEthereumClient(ethClient, accountWhite, ks, nil)
|
||||
ethereumClientGovDAO = NewEthereumClient(ethClient, accountGovDAO, ks, nil)
|
||||
ethereumClientAux = NewEthereumClient(ethClient, accountAux, ks, nil)
|
||||
ethereumClientAux2 = NewEthereumClient(ethClient, accountAux2, ks, nil)
|
||||
ethereumClientHermez = NewEthereumClient(ethClient, accountHermez, ks, nil)
|
||||
ethereumClientKep = NewEthereumClient(ethClient, hermezKeeperAccount, ks, nil)
|
||||
ethereumClientWhite = NewEthereumClient(ethClient, whiteHackGroupAccount, ks, nil)
|
||||
ethereumClientGovDAO = NewEthereumClient(ethClient, hermezGovernanceDAOAccount, ks, nil)
|
||||
ethereumClientAux = NewEthereumClient(ethClient, auxAccount, ks, nil)
|
||||
ethereumClientAux2 = NewEthereumClient(ethClient, aux2Account, ks, nil)
|
||||
ethereumClientHermez = NewEthereumClient(ethClient, hermezRollupTestAccount, ks, nil)
|
||||
|
||||
exitVal = m.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user