Browse Source

Add test to show txprocessor bug

- Test that two exits for the same account in the same batch should be merged
  into one exitInfo with the accumulated balance of both exits, in the
  txprocessor output
feature/sql-semaphore1
Eduard S 3 years ago
parent
commit
699b9deef0
1 changed files with 67 additions and 0 deletions
  1. +67
    -0
      txprocessor/txprocessor_test.go

+ 67
- 0
txprocessor/txprocessor_test.go

@ -3,6 +3,7 @@ package txprocessor
import (
"encoding/binary"
"encoding/hex"
"fmt"
"io/ioutil"
"math/big"
"os"
@ -789,3 +790,69 @@ func TestMultipleCoordIdxForTokenID(t *testing.T) {
checkBalanceByIdx(t, tp.s, 258, "100") // B
checkBalanceByIdx(t, tp.s, 259, "0") // Coord0
}
func TestTwoExits(t *testing.T) {
dir, err := ioutil.TempDir("", "tmpdb")
require.NoError(t, err)
defer assert.NoError(t, os.RemoveAll(dir))
sdb, err := statedb.NewStateDB(dir, 128, statedb.TypeSynchronizer, 32)
assert.NoError(t, err)
chainID := uint16(1)
tc := til.NewContext(chainID, common.RollupConstMaxL1UserTx)
// Two exits for the same account. The tx processor should output a
// single exit with the accumulated exit balance
set := `
Type: Blockchain
CreateAccountDeposit(0) A: 100
> batchL1 // freeze L1User{1}
> batchL1 // forge L1User{1}
ForceExit(0) A: 20
ForceExit(0) A: 20
> batchL1 // freeze L1User{2}
> batchL1 // forge L1User{2}
> block
`
blocks, err := tc.GenerateBlocks(set)
require.NoError(t, err)
err = tc.FillBlocksExtra(blocks, &til.ConfigExtra{})
require.NoError(t, err)
err = tc.FillBlocksForgedL1UserTxs(blocks)
require.NoError(t, err)
// Sanity check
require.Equal(t, 1, len(blocks[0].Rollup.Batches[1].L1UserTxs))
require.Equal(t, 2, len(blocks[0].Rollup.Batches[3].L1UserTxs))
config := Config{
NLevels: 32,
MaxFeeTx: 64,
MaxTx: 512,
MaxL1Tx: 16,
ChainID: chainID,
}
tp := NewTxProcessor(sdb, config)
ptOuts := []*ProcessTxOutput{}
for _, block := range blocks {
for _, batch := range block.Rollup.Batches {
// fmt.Printf("Batch %v\n%#v\n", batch.Batch.BatchNum, batch.L1UserTxs)
ptOut, err := tp.ProcessTxs(nil, batch.L1UserTxs, nil, nil)
require.NoError(t, err)
fmt.Printf("Exits (batch %v)\n%#v\n", batch.Batch.BatchNum, ptOut.ExitInfos)
ptOuts = append(ptOuts, ptOut)
}
}
assert.Equal(t, 1, len(ptOuts[3].ExitInfos))
assert.Equal(t, big.NewInt(40), ptOuts[3].ExitInfos[0].Balance)
acc, err := sdb.GetAccount(256)
require.NoError(t, err)
assert.Equal(t, big.NewInt(60), acc.Balance)
}

Loading…
Cancel
Save