mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Insert ETH as HistoryDB token
This commit is contained in:
@@ -3,6 +3,9 @@ package test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gobuffalo/packr/v2"
|
||||
"github.com/jmoiron/sqlx"
|
||||
migrate "github.com/rubenv/sql-migrate"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -21,3 +24,19 @@ func AssertUSD(t *testing.T, expected, actual *float64) {
|
||||
}
|
||||
*expected = *actual
|
||||
}
|
||||
|
||||
// WipeDB redo all the migrations of the SQL DB (HistoryDB and L2DB),
|
||||
// efectively recreating the original state
|
||||
func WipeDB(db *sqlx.DB) {
|
||||
migrations := &migrate.PackrMigrationSource{
|
||||
Box: packr.New("hermez-db-migrations", "../db/migrations"),
|
||||
}
|
||||
_, err := migrate.Exec(db.DB, "postgres", migrations, migrate.Down)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = migrate.Exec(db.DB, "postgres", migrations, migrate.Up)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ func GenBlocks(from, to int64) []common.Block {
|
||||
}
|
||||
|
||||
// GenTokens generates tokens. WARNING: This is meant for DB/API testing, and may not be fully consistent with the protocol.
|
||||
func GenTokens(nTokens int, blocks []common.Block) []common.Token {
|
||||
tokens := []common.Token{}
|
||||
for i := 0; i < nTokens; i++ {
|
||||
func GenTokens(nTokens int, blocks []common.Block) (tokensToAddInDB []common.Token, ethToken common.Token) {
|
||||
tokensToAddInDB = []common.Token{}
|
||||
for i := 1; i < nTokens; i++ {
|
||||
token := common.Token{
|
||||
TokenID: common.TokenID(i),
|
||||
Name: "NAME" + fmt.Sprint(i),
|
||||
@@ -41,9 +41,16 @@ func GenTokens(nTokens int, blocks []common.Block) []common.Token {
|
||||
EthBlockNum: blocks[i%len(blocks)].EthBlockNum,
|
||||
EthAddr: ethCommon.BigToAddress(big.NewInt(int64(i))),
|
||||
}
|
||||
tokens = append(tokens, token)
|
||||
tokensToAddInDB = append(tokensToAddInDB, token)
|
||||
}
|
||||
return tokensToAddInDB, common.Token{
|
||||
TokenID: 0,
|
||||
Name: "Ether",
|
||||
Symbol: "ETH",
|
||||
Decimals: 18, //nolint:gomnd
|
||||
EthBlockNum: 0,
|
||||
EthAddr: ethCommon.BigToAddress(big.NewInt(0)),
|
||||
}
|
||||
return tokens
|
||||
}
|
||||
|
||||
// GenBatches generates batches. WARNING: This is meant for DB/API testing, and may not be fully consistent with the protocol.
|
||||
|
||||
11
test/l2db.go
11
test/l2db.go
@@ -4,19 +4,8 @@ import (
|
||||
ethCrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
// CleanL2DB deletes 'tx_pool' and 'account_creation_auth' from the given DB
|
||||
func CleanL2DB(db *sqlx.DB) {
|
||||
if _, err := db.Exec("DELETE FROM tx_pool;"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if _, err := db.Exec("DELETE FROM account_creation_auth;"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// GenPoolTxs generates L2 pool txs.
|
||||
// WARNING: This tx doesn't follow the protocol (signature, txID, ...)
|
||||
// it's just to test getting/setting from/to the DB.
|
||||
|
||||
Reference in New Issue
Block a user