mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +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:
@@ -329,7 +329,7 @@ func (hdb *HistoryDB) SyncPoD(
|
||||
blockNum uint64,
|
||||
bids []common.Bid,
|
||||
coordinators []common.Coordinator,
|
||||
vars *common.AuctionVars,
|
||||
vars *common.AuctionVariables,
|
||||
) error {
|
||||
return nil
|
||||
}
|
||||
@@ -1110,40 +1110,40 @@ func (hdb *HistoryDB) AddBlockSCData(blockData *common.BlockData) (err error) {
|
||||
}
|
||||
|
||||
// Add Coordinators
|
||||
if len(blockData.Coordinators) > 0 {
|
||||
err = hdb.addCoordinators(txn, blockData.Coordinators)
|
||||
if len(blockData.Auction.Coordinators) > 0 {
|
||||
err = hdb.addCoordinators(txn, blockData.Auction.Coordinators)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Add Bids
|
||||
if len(blockData.Bids) > 0 {
|
||||
err = hdb.addBids(txn, blockData.Bids)
|
||||
if len(blockData.Auction.Bids) > 0 {
|
||||
err = hdb.addBids(txn, blockData.Auction.Bids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Add Tokens
|
||||
if len(blockData.AddedTokens) > 0 {
|
||||
err = hdb.addTokens(txn, blockData.AddedTokens)
|
||||
if len(blockData.Rollup.AddedTokens) > 0 {
|
||||
err = hdb.addTokens(txn, blockData.Rollup.AddedTokens)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Add l1 Txs
|
||||
if len(blockData.L1UserTxs) > 0 {
|
||||
err = hdb.addL1Txs(txn, blockData.L1UserTxs)
|
||||
if len(blockData.Rollup.L1UserTxs) > 0 {
|
||||
err = hdb.addL1Txs(txn, blockData.Rollup.L1UserTxs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Add Batches
|
||||
for i := range blockData.Batches {
|
||||
batch := &blockData.Batches[i]
|
||||
for i := range blockData.Rollup.Batches {
|
||||
batch := &blockData.Rollup.Batches[i]
|
||||
// Add Batch: this will trigger an update on the DB
|
||||
// that will set the batch num of forged L1 txs in this batch
|
||||
err = hdb.addBatch(txn, &batch.Batch)
|
||||
@@ -1188,6 +1188,8 @@ func (hdb *HistoryDB) AddBlockSCData(blockData *common.BlockData) (err error) {
|
||||
// TODO: INSERT CONTRACTS VARS
|
||||
}
|
||||
|
||||
// TODO: Process withdrawals
|
||||
|
||||
return txn.Commit()
|
||||
}
|
||||
|
||||
|
||||
@@ -408,7 +408,7 @@ func TestGetL1UserTxs(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
// Sanity check
|
||||
require.Equal(t, 1, len(blocks))
|
||||
require.Equal(t, 5, len(blocks[0].L1UserTxs))
|
||||
require.Equal(t, 5, len(blocks[0].Rollup.L1UserTxs))
|
||||
// fmt.Printf("DBG Blocks: %+v\n", blocks)
|
||||
|
||||
toForgeL1TxsNum := int64(1)
|
||||
@@ -421,7 +421,7 @@ func TestGetL1UserTxs(t *testing.T) {
|
||||
l1UserTxs, err := historyDB.GetL1UserTxs(toForgeL1TxsNum)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 5, len(l1UserTxs))
|
||||
assert.Equal(t, blocks[0].L1UserTxs, l1UserTxs)
|
||||
assert.Equal(t, blocks[0].Rollup.L1UserTxs, l1UserTxs)
|
||||
|
||||
// No l1UserTxs for this toForgeL1TxsNum
|
||||
l1UserTxs, err = historyDB.GetL1UserTxs(2)
|
||||
|
||||
Reference in New Issue
Block a user