mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Feature/merge history l2 tables (#156)
* WIP rebase * Combine both SQL DBs * API and DB refactor
This commit is contained in:
44
test/l2db.go
44
test/l2db.go
@@ -24,7 +24,7 @@ func CleanL2DB(db *sqlx.DB) {
|
||||
// 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.
|
||||
func GenPoolTxs(n int) []*common.PoolL2Tx {
|
||||
func GenPoolTxs(n int, tokens []common.Token) []*common.PoolL2Tx {
|
||||
txs := make([]*common.PoolL2Tx, 0, n)
|
||||
privK := babyjub.NewRandPrivKey()
|
||||
for i := 0; i < n; i++ {
|
||||
@@ -44,21 +44,33 @@ func GenPoolTxs(n int) []*common.PoolL2Tx {
|
||||
}
|
||||
f := new(big.Float).SetInt(big.NewInt(int64(i)))
|
||||
amountF, _ := f.Float64()
|
||||
var usd, absFee *float64
|
||||
fee := common.FeeSelector(i % 255) //nolint:gomnd
|
||||
token := tokens[i%len(tokens)]
|
||||
if token.USD != nil {
|
||||
usd = new(float64)
|
||||
absFee = new(float64)
|
||||
*usd = *token.USD * amountF
|
||||
*absFee = fee.Percentage() * *usd
|
||||
}
|
||||
tx := &common.PoolL2Tx{
|
||||
TxID: common.TxID(common.Hash([]byte(strconv.Itoa(i)))),
|
||||
FromIdx: common.Idx(i),
|
||||
ToIdx: common.Idx(i + 1),
|
||||
ToEthAddr: ethCommon.BigToAddress(big.NewInt(int64(i))),
|
||||
ToBJJ: privK.Public(),
|
||||
TokenID: common.TokenID(i),
|
||||
Amount: big.NewInt(int64(i)),
|
||||
AmountFloat: amountF,
|
||||
//nolint:gomnd
|
||||
Fee: common.FeeSelector(i % 255),
|
||||
Nonce: common.Nonce(i),
|
||||
State: state,
|
||||
Signature: privK.SignPoseidon(big.NewInt(int64(i))),
|
||||
Timestamp: time.Now().UTC(),
|
||||
TxID: common.TxID(common.Hash([]byte(strconv.Itoa(i)))),
|
||||
FromIdx: common.Idx(i),
|
||||
ToIdx: common.Idx(i + 1),
|
||||
ToEthAddr: ethCommon.BigToAddress(big.NewInt(int64(i))),
|
||||
ToBJJ: privK.Public(),
|
||||
TokenID: token.TokenID,
|
||||
Amount: big.NewInt(int64(i)),
|
||||
AmountFloat: amountF,
|
||||
USD: usd,
|
||||
Fee: fee,
|
||||
Nonce: common.Nonce(i),
|
||||
State: state,
|
||||
Signature: privK.SignPoseidon(big.NewInt(int64(i))),
|
||||
Timestamp: time.Now().UTC(),
|
||||
TokenSymbol: token.Symbol,
|
||||
AbsoluteFee: absFee,
|
||||
AbsoluteFeeUpdate: token.USDUpdate,
|
||||
}
|
||||
if i%2 == 0 { // Optional parameters: rq
|
||||
tx.RqFromIdx = common.Idx(i)
|
||||
@@ -72,8 +84,6 @@ func GenPoolTxs(n int) []*common.PoolL2Tx {
|
||||
}
|
||||
if i%3 == 0 { // Optional parameters: things that get updated "a posteriori"
|
||||
tx.BatchNum = 489
|
||||
tx.AbsoluteFee = 39.12345
|
||||
tx.AbsoluteFeeUpdate = time.Now().UTC()
|
||||
}
|
||||
txs = append(txs, tx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user