ProcessTxs fees collct update & tests, and other:

- Update StateDB ProcessTxs fees collection
- Update ProcessTxs tests to last StateDB & Til changes
- Til Blockchain L2Txs remove Nonce generation, update tests accordingly
- Update Til Set to test fees
This commit is contained in:
arnaucube
2020-10-28 17:10:31 +01:00
parent 90db8a1106
commit 2338b6b90b
7 changed files with 170 additions and 89 deletions

View File

@@ -10,6 +10,8 @@ AddToken(1)
AddToken(2)
AddToken(3)
// block:0 batch:0
// Coordinator accounts, Idxs: 256, 257, 258, 259
CreateAccountCoordinator(0) Coord
CreateAccountCoordinator(1) Coord
@@ -17,11 +19,12 @@ CreateAccountCoordinator(2) Coord
CreateAccountCoordinator(3) Coord
> batch
// block:0 batch:1
// deposits TokenID: 1
CreateAccountDeposit(1) A: 50
CreateAccountDeposit(1) B: 5
CreateAccountDeposit(1) C: 20
CreateAccountDeposit(1) C: 200
CreateAccountDeposit(1) D: 25
CreateAccountDeposit(1) E: 25
CreateAccountDeposit(1) F: 25
@@ -55,6 +58,7 @@ CreateAccountDeposit(0) B: 10000
CreateAccountDeposit(0) C: 1
> batchL1
// block:0 batch:2
// transactions TokenID: 1
Transfer(1) A-B: 5 (1)
@@ -63,7 +67,7 @@ Transfer(1) A-M: 5 (1)
Transfer(1) A-N: 5 (1)
Transfer(1) A-O: 5 (1)
Transfer(1) B-C: 3 (1)
Transfer(1) C-A: 3 (255)
Transfer(1) C-A: 10 (200)
Transfer(1) D-A: 5 (1)
Transfer(1) D-Z: 5 (1)
Transfer(1) D-Y: 5 (1)
@@ -82,9 +86,15 @@ Transfer(0) B-C: 50 (192)
> batchL1
> block
// block:1 batch:0
// A (3) still does not exist, coordinator should create new L1Tx to create the account
CreateAccountCoordinator(3) A
Transfer(1) A-B: 1 (1)
Transfer(1) A-B: 1 (1)
Transfer(1) A-B: 1 (1)
Transfer(3) B-A: 5 (1)
Transfer(2) A-B: 5 (1)
Transfer(1) I-K: 3 (1)
@@ -132,7 +142,7 @@ Transfer(1) W-J: 3 (1)
Transfer(1) W-A: 5 (1)
Transfer(1) W-Z: 5 (1)
Transfer(1) X-B: 5 (1)
Transfer(1) X-C: 5 (50)
Transfer(1) X-C: 10 (200)
Transfer(1) X-D: 5 (1)
Transfer(1) X-E: 5 (1)
Transfer(1) Y-B: 5 (1)
@@ -148,6 +158,7 @@ Exit(1) Y: 5 (1)
Exit(1) Z: 5 (1)
> batch
// block:1 batch:1
Deposit(1) A: 50
Deposit(1) B: 5

View File

@@ -385,7 +385,10 @@ func (tc *Context) setIdxs() error {
}
}
tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID].Nonce++
testTx.L2Tx.Nonce = tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID].Nonce
// next line is commented to avoid Blockchain L2Txs to have
// Nonce different from 0, as from Blockchain those
// transactions will come without Nonce
// testTx.L2Tx.Nonce = tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID].Nonce
// set real Idx
testTx.L2Tx.FromIdx = tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID].Idx

View File

@@ -110,36 +110,36 @@ func TestGenerateBlocks(t *testing.T) {
// // #4: CreateAccountDeposit(1) D: 5
tc.checkL1TxParams(t, blocks[0].L1UserTxs[4], common.TxTypeCreateAccountDeposit, 1, "D", "", big.NewInt(5), nil)
// #5: Transfer(1) A-B: 6 (1)
tc.checkL2TxParams(t, blocks[0].Batches[2].L2Txs[0], common.TxTypeTransfer, 1, "A", "B", big.NewInt(6), common.BatchNum(3), common.Nonce(1))
tc.checkL2TxParams(t, blocks[0].Batches[2].L2Txs[0], common.TxTypeTransfer, 1, "A", "B", big.NewInt(6), common.BatchNum(3))
// #6: Transfer(1) B-D: 3 (1)
tc.checkL2TxParams(t, blocks[0].Batches[2].L2Txs[1], common.TxTypeTransfer, 1, "B", "D", big.NewInt(3), common.BatchNum(3), common.Nonce(1))
tc.checkL2TxParams(t, blocks[0].Batches[2].L2Txs[1], common.TxTypeTransfer, 1, "B", "D", big.NewInt(3), common.BatchNum(3))
// #7: Transfer(1) A-D: 1 (1)
tc.checkL2TxParams(t, blocks[0].Batches[2].L2Txs[2], common.TxTypeTransfer, 1, "A", "D", big.NewInt(1), common.BatchNum(3), common.Nonce(2))
tc.checkL2TxParams(t, blocks[0].Batches[2].L2Txs[2], common.TxTypeTransfer, 1, "A", "D", big.NewInt(1), common.BatchNum(3))
// change of Batch
// #8: CreateAccountDepositTransfer(1) F-A: 15, 10 (3)
tc.checkL1TxParams(t, blocks[0].L1UserTxs[5], common.TxTypeCreateAccountDepositTransfer, 1, "F", "A", big.NewInt(15), big.NewInt(10))
// #9: DepositTransfer(1) A-B: 15, 10 (1)
tc.checkL1TxParams(t, blocks[0].L1UserTxs[6], common.TxTypeDepositTransfer, 1, "A", "B", big.NewInt(15), big.NewInt(10))
// #11: Transfer(1) C-A : 3 (1)
tc.checkL2TxParams(t, blocks[0].Batches[3].L2Txs[0], common.TxTypeTransfer, 1, "C", "A", big.NewInt(3), common.BatchNum(4), common.Nonce(1))
tc.checkL2TxParams(t, blocks[0].Batches[3].L2Txs[0], common.TxTypeTransfer, 1, "C", "A", big.NewInt(3), common.BatchNum(4))
// #12: Transfer(2) A-B: 15 (1)
tc.checkL2TxParams(t, blocks[0].Batches[3].L2Txs[1], common.TxTypeTransfer, 2, "A", "B", big.NewInt(15), common.BatchNum(4), common.Nonce(1))
tc.checkL2TxParams(t, blocks[0].Batches[3].L2Txs[1], common.TxTypeTransfer, 2, "A", "B", big.NewInt(15), common.BatchNum(4))
// #13: Deposit(1) User0: 20
tc.checkL1TxParams(t, blocks[0].L1UserTxs[7], common.TxTypeCreateAccountDeposit, 1, "User0", "", big.NewInt(20), nil)
// // #14: Deposit(3) User1: 20
tc.checkL1TxParams(t, blocks[0].L1UserTxs[8], common.TxTypeCreateAccountDeposit, 3, "User1", "", big.NewInt(20), nil)
// #15: Transfer(1) User0-User1: 15 (1)
tc.checkL2TxParams(t, blocks[0].Batches[4].L2Txs[0], common.TxTypeTransfer, 1, "User0", "User1", big.NewInt(15), common.BatchNum(5), common.Nonce(1))
tc.checkL2TxParams(t, blocks[0].Batches[4].L2Txs[0], common.TxTypeTransfer, 1, "User0", "User1", big.NewInt(15), common.BatchNum(5))
// #16: Transfer(3) User1-User0: 15 (1)
tc.checkL2TxParams(t, blocks[0].Batches[4].L2Txs[1], common.TxTypeTransfer, 3, "User1", "User0", big.NewInt(15), common.BatchNum(5), common.Nonce(1))
tc.checkL2TxParams(t, blocks[0].Batches[4].L2Txs[1], common.TxTypeTransfer, 3, "User1", "User0", big.NewInt(15), common.BatchNum(5))
// #17: Transfer(1) A-C: 1 (1)
tc.checkL2TxParams(t, blocks[0].Batches[4].L2Txs[2], common.TxTypeTransfer, 1, "A", "C", big.NewInt(1), common.BatchNum(5), common.Nonce(4))
tc.checkL2TxParams(t, blocks[0].Batches[4].L2Txs[2], common.TxTypeTransfer, 1, "A", "C", big.NewInt(1), common.BatchNum(5))
// change of Batch
// #18: Transfer(1) User1-User0: 1 (1)
tc.checkL2TxParams(t, blocks[1].Batches[0].L2Txs[0], common.TxTypeTransfer, 1, "User1", "User0", big.NewInt(1), common.BatchNum(6), common.Nonce(1))
tc.checkL2TxParams(t, blocks[1].Batches[0].L2Txs[0], common.TxTypeTransfer, 1, "User1", "User0", big.NewInt(1), common.BatchNum(6))
// change of Block (implies also a change of batch)
// #19: Transfer(1) A-B: 1 (1)
tc.checkL2TxParams(t, blocks[1].Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6), common.Nonce(5))
tc.checkL2TxParams(t, blocks[1].Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6))
}
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, loadAmount, amount *big.Int) {
@@ -160,7 +160,7 @@ func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxTy
}
}
func (tc *Context) checkL2TxParams(t *testing.T, tx common.L2Tx, typ common.TxType, tokenID common.TokenID, from, to string, amount *big.Int, batchNum common.BatchNum, nonce common.Nonce) {
func (tc *Context) checkL2TxParams(t *testing.T, tx common.L2Tx, typ common.TxType, tokenID common.TokenID, from, to string, amount *big.Int, batchNum common.BatchNum) {
assert.Equal(t, typ, tx.Type)
assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
if tx.Type != common.TxTypeExit {
@@ -170,7 +170,6 @@ func (tc *Context) checkL2TxParams(t *testing.T, tx common.L2Tx, typ common.TxTy
assert.Equal(t, amount, tx.Amount)
}
assert.Equal(t, batchNum, tx.BatchNum)
assert.Equal(t, nonce, tx.Nonce)
}
func TestGeneratePoolL2Txs(t *testing.T) {