mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Test purger, fix some nonces
- Test all the purger functions - Fix nonces set by til (previously til started with nonce 1 for pool l2txs, but the correct implementation is to start with nonce 0) - Rename L2DB.CheckNonces to L2DB.invalidateOldNoncesQuery - Rename L2DB.checkNoncesQuery to L2DB.InvalidateOldNonces Related https://github.com/hermeznetwork/hermez-node/issues/392 (Fix checkNoncesQuery) Resolve https://github.com/hermeznetwork/hermez-node/issues/396
This commit is contained in:
@@ -597,7 +597,6 @@ func (tc *Context) generatePoolL2Txs() ([]common.PoolL2Tx, error) {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
|
||||
}
|
||||
}
|
||||
tc.Users[inst.From].Accounts[inst.TokenID].Nonce++
|
||||
// if account of receiver does not exist, don't use
|
||||
// ToIdx, and use only ToEthAddr & ToBJJ
|
||||
tx := common.PoolL2Tx{
|
||||
@@ -612,6 +611,7 @@ func (tc *Context) generatePoolL2Txs() ([]common.PoolL2Tx, error) {
|
||||
RqToBJJ: common.EmptyBJJComp,
|
||||
Type: inst.Typ,
|
||||
}
|
||||
tc.Users[inst.From].Accounts[inst.TokenID].Nonce++
|
||||
if tx.Type == common.TxTypeTransfer {
|
||||
tx.ToIdx = tc.Users[inst.To].Accounts[inst.TokenID].Idx
|
||||
tx.ToEthAddr = tc.Users[inst.To].Addr
|
||||
@@ -639,7 +639,6 @@ func (tc *Context) generatePoolL2Txs() ([]common.PoolL2Tx, error) {
|
||||
|
||||
txs = append(txs, tx)
|
||||
case common.TxTypeExit:
|
||||
tc.Users[inst.From].Accounts[inst.TokenID].Nonce++
|
||||
tx := common.PoolL2Tx{
|
||||
FromIdx: tc.Users[inst.From].Accounts[inst.TokenID].Idx,
|
||||
ToIdx: common.Idx(1), // as is an Exit
|
||||
@@ -650,6 +649,7 @@ func (tc *Context) generatePoolL2Txs() ([]common.PoolL2Tx, error) {
|
||||
State: common.PoolL2TxStatePending,
|
||||
Type: common.TxTypeExit,
|
||||
}
|
||||
tc.Users[inst.From].Accounts[inst.TokenID].Nonce++
|
||||
nTx, err := common.NewPoolL2Tx(&tx)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
|
||||
|
||||
@@ -218,9 +218,9 @@ func TestGeneratePoolL2Txs(t *testing.T) {
|
||||
assert.Equal(t, tc.Users["User1"].Addr.Hex(), poolL2Txs[5].ToEthAddr.Hex())
|
||||
assert.Equal(t, tc.Users["User1"].BJJ.Public().String(), poolL2Txs[5].ToBJJ.String())
|
||||
|
||||
assert.Equal(t, common.Nonce(1), poolL2Txs[0].Nonce)
|
||||
assert.Equal(t, common.Nonce(2), poolL2Txs[3].Nonce)
|
||||
assert.Equal(t, common.Nonce(3), poolL2Txs[8].Nonce)
|
||||
assert.Equal(t, common.Nonce(0), poolL2Txs[0].Nonce)
|
||||
assert.Equal(t, common.Nonce(1), poolL2Txs[3].Nonce)
|
||||
assert.Equal(t, common.Nonce(2), poolL2Txs[8].Nonce)
|
||||
|
||||
assert.Equal(t, tc.Users["B"].Addr.Hex(), poolL2Txs[9].ToEthAddr.Hex())
|
||||
assert.Equal(t, common.EmptyBJJComp, poolL2Txs[9].ToBJJ)
|
||||
@@ -238,9 +238,9 @@ func TestGeneratePoolL2Txs(t *testing.T) {
|
||||
`
|
||||
poolL2Txs, err = tc.GeneratePoolL2Txs(set)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, common.Nonce(6), poolL2Txs[0].Nonce)
|
||||
assert.Equal(t, common.Nonce(2), poolL2Txs[1].Nonce)
|
||||
assert.Equal(t, common.Nonce(7), poolL2Txs[2].Nonce)
|
||||
assert.Equal(t, common.Nonce(5), poolL2Txs[0].Nonce)
|
||||
assert.Equal(t, common.Nonce(1), poolL2Txs[1].Nonce)
|
||||
assert.Equal(t, common.Nonce(6), poolL2Txs[2].Nonce)
|
||||
|
||||
// check that a PoolL2Tx can be done to a non existing ToIdx
|
||||
set = `
|
||||
|
||||
Reference in New Issue
Block a user