mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Add lll to linter checks
Updated: batchbuilder common coordinator db/statedb eth log node priceupdater prover synchronizer test/* txprocessor txselector Pending (once https://github.com/hermeznetwork/hermez-node/tree/feature/serveapicli is merged to master): Update golangci-lint version to v1.37.1 api apitypes cli config db/historydb db/l2db
This commit is contained in:
@@ -310,7 +310,8 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
|
||||
} else if lit == "PoolL2" {
|
||||
return &Instruction{Typ: "PoolL2"}, setTypeLine
|
||||
} else {
|
||||
return c, tracerr.Wrap(fmt.Errorf("Invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", lit))
|
||||
return c,
|
||||
tracerr.Wrap(fmt.Errorf("Invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", lit))
|
||||
}
|
||||
} else if lit == "AddToken" {
|
||||
if err := p.expectChar(c, "("); err != nil {
|
||||
@@ -391,7 +392,9 @@ func (p *parser) parseLine(setType setType) (*Instruction, error) {
|
||||
return c, tracerr.Wrap(fmt.Errorf("Unexpected PoolL2 tx type: %s", lit))
|
||||
}
|
||||
} else {
|
||||
return c, tracerr.Wrap(fmt.Errorf("Invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", setType))
|
||||
return c,
|
||||
tracerr.Wrap(fmt.Errorf("Invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'",
|
||||
setType))
|
||||
}
|
||||
|
||||
if err := p.expectChar(c, "("); err != nil {
|
||||
@@ -522,14 +525,18 @@ func (p *parser) parse() (*parsedSet, error) {
|
||||
}
|
||||
if tracerr.Unwrap(err) == setTypeLine {
|
||||
if ps.typ != "" {
|
||||
return ps, tracerr.Wrap(fmt.Errorf("Line %d: Instruction of 'Type: %s' when there is already a previous instruction 'Type: %s' defined", i, instruction.Typ, ps.typ))
|
||||
return ps,
|
||||
tracerr.Wrap(fmt.Errorf("Line %d: Instruction of 'Type: %s' when "+
|
||||
"there is already a previous instruction 'Type: %s' defined",
|
||||
i, instruction.Typ, ps.typ))
|
||||
}
|
||||
if instruction.Typ == "PoolL2" {
|
||||
ps.typ = SetTypePoolL2
|
||||
} else if instruction.Typ == "Blockchain" {
|
||||
ps.typ = SetTypeBlockchain
|
||||
} else {
|
||||
log.Fatalf("Line %d: Invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", i, instruction.Typ)
|
||||
log.Fatalf("Line %d: Invalid set type: '%s'. Valid set types: "+
|
||||
"'Blockchain', 'PoolL2'", i, instruction.Typ)
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -552,7 +559,9 @@ func (p *parser) parse() (*parsedSet, error) {
|
||||
}
|
||||
ps.instructions = append(ps.instructions, *instruction)
|
||||
users[instruction.From] = true
|
||||
if instruction.Typ == common.TxTypeTransfer || instruction.Typ == common.TxTypeTransferToEthAddr || instruction.Typ == common.TxTypeTransferToBJJ { // type: Transfer
|
||||
if instruction.Typ == common.TxTypeTransfer ||
|
||||
instruction.Typ == common.TxTypeTransferToEthAddr ||
|
||||
instruction.Typ == common.TxTypeTransferToBJJ { // type: Transfer
|
||||
users[instruction.To] = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,12 +72,19 @@ func TestParseBlockchainTxs(t *testing.T) {
|
||||
assert.Equal(t, TxTypeCreateAccountDepositCoordinator, instructions.instructions[7].Typ)
|
||||
assert.Equal(t, TypeNewBatch, instructions.instructions[11].Typ)
|
||||
assert.Equal(t, "Deposit(1)User0:20", instructions.instructions[16].raw())
|
||||
assert.Equal(t, "Type: DepositTransfer, From: A, To: B, DepositAmount: 15, Amount: 10, Fee: 0, TokenID: 1\n", instructions.instructions[13].String())
|
||||
assert.Equal(t, "Type: Transfer, From: User1, To: User0, Amount: 15, Fee: 1, TokenID: 3\n", instructions.instructions[19].String())
|
||||
assert.Equal(t,
|
||||
"Type: DepositTransfer, From: A, To: B, DepositAmount: 15, Amount: 10, Fee: 0, TokenID: 1\n",
|
||||
instructions.instructions[13].String())
|
||||
assert.Equal(t,
|
||||
"Type: Transfer, From: User1, To: User0, Amount: 15, Fee: 1, TokenID: 3\n",
|
||||
instructions.instructions[19].String())
|
||||
assert.Equal(t, "Transfer(2)A-B:15(1)", instructions.instructions[15].raw())
|
||||
assert.Equal(t, "Type: Transfer, From: A, To: B, Amount: 15, Fee: 1, TokenID: 2\n", instructions.instructions[15].String())
|
||||
assert.Equal(t,
|
||||
"Type: Transfer, From: A, To: B, Amount: 15, Fee: 1, TokenID: 2\n",
|
||||
instructions.instructions[15].String())
|
||||
assert.Equal(t, "Exit(1)A:5", instructions.instructions[24].raw())
|
||||
assert.Equal(t, "Type: Exit, From: A, Amount: 5, TokenID: 1\n", instructions.instructions[24].String())
|
||||
assert.Equal(t, "Type: Exit, From: A, Amount: 5, TokenID: 1\n",
|
||||
instructions.instructions[24].String())
|
||||
}
|
||||
|
||||
func TestParsePoolTxs(t *testing.T) {
|
||||
@@ -158,7 +165,9 @@ func TestParseErrors(t *testing.T) {
|
||||
`
|
||||
parser = newParser(strings.NewReader(s))
|
||||
_, err = parser.parse()
|
||||
assert.Equal(t, "Line 2: Transfer(1)A-B:10(256)\n, err: Fee 256 can not be bigger than 255", err.Error())
|
||||
assert.Equal(t,
|
||||
"Line 2: Transfer(1)A-B:10(256)\n, err: Fee 256 can not be bigger than 255",
|
||||
err.Error())
|
||||
|
||||
// check that the PoolTransfer & Transfer are only accepted in the
|
||||
// correct case case (PoolTxs/BlockchainTxs)
|
||||
@@ -175,7 +184,9 @@ func TestParseErrors(t *testing.T) {
|
||||
`
|
||||
parser = newParser(strings.NewReader(s))
|
||||
_, err = parser.parse()
|
||||
assert.Equal(t, "Line 2: PoolTransfer, err: Unexpected Blockchain tx type: PoolTransfer", err.Error())
|
||||
assert.Equal(t,
|
||||
"Line 2: PoolTransfer, err: Unexpected Blockchain tx type: PoolTransfer",
|
||||
err.Error())
|
||||
|
||||
s = `
|
||||
Type: Blockchain
|
||||
@@ -183,7 +194,9 @@ func TestParseErrors(t *testing.T) {
|
||||
`
|
||||
parser = newParser(strings.NewReader(s))
|
||||
_, err = parser.parse()
|
||||
assert.Equal(t, "Line 2: >, err: Unexpected '> btch', expected '> batch' or '> block'", err.Error())
|
||||
assert.Equal(t,
|
||||
"Line 2: >, err: Unexpected '> btch', expected '> batch' or '> block'",
|
||||
err.Error())
|
||||
|
||||
// check definition of set Type
|
||||
s = `PoolTransfer(1) A-B: 10 (1)`
|
||||
@@ -193,17 +206,23 @@ func TestParseErrors(t *testing.T) {
|
||||
s = `Type: PoolL1`
|
||||
parser = newParser(strings.NewReader(s))
|
||||
_, err = parser.parse()
|
||||
assert.Equal(t, "Line 1: Type:, err: Invalid set type: 'PoolL1'. Valid set types: 'Blockchain', 'PoolL2'", err.Error())
|
||||
assert.Equal(t,
|
||||
"Line 1: Type:, err: Invalid set type: 'PoolL1'. Valid set types: 'Blockchain', 'PoolL2'",
|
||||
err.Error())
|
||||
s = `Type: PoolL1
|
||||
Type: Blockchain`
|
||||
parser = newParser(strings.NewReader(s))
|
||||
_, err = parser.parse()
|
||||
assert.Equal(t, "Line 1: Type:, err: Invalid set type: 'PoolL1'. Valid set types: 'Blockchain', 'PoolL2'", err.Error())
|
||||
assert.Equal(t,
|
||||
"Line 1: Type:, err: Invalid set type: 'PoolL1'. Valid set types: 'Blockchain', 'PoolL2'",
|
||||
err.Error())
|
||||
s = `Type: PoolL2
|
||||
Type: Blockchain`
|
||||
parser = newParser(strings.NewReader(s))
|
||||
_, err = parser.parse()
|
||||
assert.Equal(t, "Line 2: Instruction of 'Type: Blockchain' when there is already a previous instruction 'Type: PoolL2' defined", err.Error())
|
||||
assert.Equal(t,
|
||||
"Line 2: Instruction of 'Type: Blockchain' when there is already a previous "+
|
||||
"instruction 'Type: PoolL2' defined", err.Error())
|
||||
|
||||
s = `Type: Blockchain
|
||||
AddToken(1)
|
||||
|
||||
@@ -161,7 +161,9 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
if parsedSet.typ != SetTypeBlockchain {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Expected set type: %s, found: %s", SetTypeBlockchain, parsedSet.typ))
|
||||
return nil,
|
||||
tracerr.Wrap(fmt.Errorf("Expected set type: %s, found: %s",
|
||||
SetTypeBlockchain, parsedSet.typ))
|
||||
}
|
||||
|
||||
tc.instructions = parsedSet.instructions
|
||||
@@ -209,7 +211,9 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
TokenID: inst.TokenID,
|
||||
Amount: big.NewInt(0),
|
||||
DepositAmount: big.NewInt(0),
|
||||
Type: common.TxTypeCreateAccountDeposit, // as TxTypeCreateAccountDepositCoordinator is not valid oustide Til package
|
||||
// as TxTypeCreateAccountDepositCoordinator is
|
||||
// not valid oustide Til package
|
||||
Type: common.TxTypeCreateAccountDeposit,
|
||||
}
|
||||
testTx := L1Tx{
|
||||
lineNum: inst.LineNum,
|
||||
@@ -218,7 +222,8 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
}
|
||||
|
||||
tc.currBatchTest.l1CoordinatorTxs = append(tc.currBatchTest.l1CoordinatorTxs, testTx)
|
||||
case common.TxTypeCreateAccountDeposit, common.TxTypeCreateAccountDepositTransfer: // tx source: L1UserTx
|
||||
case common.TxTypeCreateAccountDeposit, common.TxTypeCreateAccountDepositTransfer:
|
||||
// tx source: L1UserTx
|
||||
if err := tc.checkIfTokenIsRegistered(inst); err != nil {
|
||||
log.Error(err)
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Line %d: %s", inst.LineNum, err.Error()))
|
||||
@@ -281,7 +286,8 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
Type: common.TxTypeTransfer,
|
||||
EthBlockNum: tc.blockNum,
|
||||
}
|
||||
tx.BatchNum = common.BatchNum(tc.currBatchNum) // when converted to PoolL2Tx BatchNum parameter is lost
|
||||
// when converted to PoolL2Tx BatchNum parameter is lost
|
||||
tx.BatchNum = common.BatchNum(tc.currBatchNum)
|
||||
testTx := L2Tx{
|
||||
lineNum: inst.LineNum,
|
||||
fromIdxName: inst.From,
|
||||
@@ -322,7 +328,8 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
Type: common.TxTypeExit,
|
||||
EthBlockNum: tc.blockNum,
|
||||
}
|
||||
tx.BatchNum = common.BatchNum(tc.currBatchNum) // when converted to PoolL2Tx BatchNum parameter is lost
|
||||
// when converted to PoolL2Tx BatchNum parameter is lost
|
||||
tx.BatchNum = common.BatchNum(tc.currBatchNum)
|
||||
testTx := L2Tx{
|
||||
lineNum: inst.LineNum,
|
||||
fromIdxName: inst.From,
|
||||
@@ -395,7 +402,10 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
|
||||
EthBlockNum: tc.blockNum,
|
||||
}
|
||||
if inst.TokenID != tc.LastRegisteredTokenID+1 {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Line %d: AddToken TokenID should be sequential, expected TokenID: %d, defined TokenID: %d", inst.LineNum, tc.LastRegisteredTokenID+1, inst.TokenID))
|
||||
return nil,
|
||||
tracerr.Wrap(fmt.Errorf("Line %d: AddToken TokenID should be "+
|
||||
"sequential, expected TokenID: %d, defined TokenID: %d",
|
||||
inst.LineNum, tc.LastRegisteredTokenID+1, inst.TokenID))
|
||||
}
|
||||
tc.LastRegisteredTokenID++
|
||||
tc.currBlock.Rollup.AddedTokens = append(tc.currBlock.Rollup.AddedTokens, newToken)
|
||||
@@ -413,9 +423,13 @@ func (tc *Context) calculateIdxForL1Txs(isCoordinatorTxs bool, txs []L1Tx) error
|
||||
// for each batch.L1CoordinatorTxs of the Queues[ToForgeNum], calculate the Idx
|
||||
for i := 0; i < len(txs); i++ {
|
||||
tx := txs[i]
|
||||
if tx.L1Tx.Type == common.TxTypeCreateAccountDeposit || tx.L1Tx.Type == common.TxTypeCreateAccountDepositTransfer {
|
||||
if tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID] != nil { // if account already exists, return error
|
||||
return tracerr.Wrap(fmt.Errorf("Can not create same account twice (same User (%s) & same TokenID (%d)) (this is a design property of Til)", tx.fromIdxName, tx.L1Tx.TokenID))
|
||||
if tx.L1Tx.Type == common.TxTypeCreateAccountDeposit ||
|
||||
tx.L1Tx.Type == common.TxTypeCreateAccountDepositTransfer {
|
||||
if tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID] != nil {
|
||||
// if account already exists, return error
|
||||
return tracerr.Wrap(fmt.Errorf("Can not create same account twice "+
|
||||
"(same User (%s) & same TokenID (%d)) (this is a design property of Til)",
|
||||
tx.fromIdxName, tx.L1Tx.TokenID))
|
||||
}
|
||||
tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID] = &Account{
|
||||
Idx: common.Idx(tc.idx),
|
||||
@@ -423,7 +437,8 @@ func (tc *Context) calculateIdxForL1Txs(isCoordinatorTxs bool, txs []L1Tx) error
|
||||
Nonce: common.Nonce(0),
|
||||
BatchNum: tc.currBatchNum,
|
||||
}
|
||||
tc.l1CreatedAccounts[idxTokenIDToString(tx.fromIdxName, tx.L1Tx.TokenID)] = tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID]
|
||||
tc.l1CreatedAccounts[idxTokenIDToString(tx.fromIdxName, tx.L1Tx.TokenID)] =
|
||||
tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID]
|
||||
tc.accountsByIdx[tc.idx] = tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID]
|
||||
tc.UsersByIdx[tc.idx] = tc.Users[tx.fromIdxName]
|
||||
tc.idx++
|
||||
@@ -442,11 +457,15 @@ func (tc *Context) setIdxs() error {
|
||||
testTx := &tc.currBatchTest.l2Txs[i]
|
||||
|
||||
if tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID] == nil {
|
||||
return tracerr.Wrap(fmt.Errorf("Line %d: %s from User %s for TokenID %d while account not created yet", testTx.lineNum, testTx.L2Tx.Type, testTx.fromIdxName, testTx.tokenID))
|
||||
return tracerr.Wrap(fmt.Errorf("Line %d: %s from User %s for TokenID %d "+
|
||||
"while account not created yet",
|
||||
testTx.lineNum, testTx.L2Tx.Type, testTx.fromIdxName, testTx.tokenID))
|
||||
}
|
||||
if testTx.L2Tx.Type == common.TxTypeTransfer {
|
||||
if _, ok := tc.l1CreatedAccounts[idxTokenIDToString(testTx.toIdxName, testTx.tokenID)]; !ok {
|
||||
return tracerr.Wrap(fmt.Errorf("Line %d: Can not create Transfer for a non existing account. Batch %d, ToIdx name: %s, TokenID: %d", testTx.lineNum, tc.currBatchNum, testTx.toIdxName, testTx.tokenID))
|
||||
return tracerr.Wrap(fmt.Errorf("Line %d: Can not create Transfer for a non "+
|
||||
"existing account. Batch %d, ToIdx name: %s, TokenID: %d",
|
||||
testTx.lineNum, tc.currBatchNum, testTx.toIdxName, testTx.tokenID))
|
||||
}
|
||||
}
|
||||
tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID].Nonce++
|
||||
@@ -498,7 +517,8 @@ func (tc *Context) addToL1UserQueue(tx L1Tx) error {
|
||||
tx.L1Tx.Position = len(tc.Queues[tc.openToForge])
|
||||
|
||||
// When an L1UserTx is generated, all idxs must be available (except when idx == 0 or idx == 1)
|
||||
if tx.L1Tx.Type != common.TxTypeCreateAccountDeposit && tx.L1Tx.Type != common.TxTypeCreateAccountDepositTransfer {
|
||||
if tx.L1Tx.Type != common.TxTypeCreateAccountDeposit &&
|
||||
tx.L1Tx.Type != common.TxTypeCreateAccountDepositTransfer {
|
||||
tx.L1Tx.FromIdx = tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID].Idx
|
||||
}
|
||||
tx.L1Tx.FromEthAddr = tc.Users[tx.fromIdxName].Addr
|
||||
@@ -530,14 +550,16 @@ func (tc *Context) addToL1UserQueue(tx L1Tx) error {
|
||||
|
||||
func (tc *Context) checkIfAccountExists(tf string, inst Instruction) error {
|
||||
if tc.Users[tf].Accounts[inst.TokenID] == nil {
|
||||
return tracerr.Wrap(fmt.Errorf("%s at User: %s, for TokenID: %d, while account not created yet", inst.Typ, tf, inst.TokenID))
|
||||
return tracerr.Wrap(fmt.Errorf("%s at User: %s, for TokenID: %d, while account not created yet",
|
||||
inst.Typ, tf, inst.TokenID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tc *Context) checkIfTokenIsRegistered(inst Instruction) error {
|
||||
if inst.TokenID > tc.LastRegisteredTokenID {
|
||||
return tracerr.Wrap(fmt.Errorf("Can not process %s: TokenID %d not registered, last registered TokenID: %d", inst.Typ, inst.TokenID, tc.LastRegisteredTokenID))
|
||||
return tracerr.Wrap(fmt.Errorf("Can not process %s: TokenID %d not registered, "+
|
||||
"last registered TokenID: %d", inst.Typ, inst.TokenID, tc.LastRegisteredTokenID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -551,7 +573,8 @@ func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
if parsedSet.typ != SetTypePoolL2 {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Expected set type: %s, found: %s", SetTypePoolL2, parsedSet.typ))
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Expected set type: %s, found: %s",
|
||||
SetTypePoolL2, parsedSet.typ))
|
||||
}
|
||||
|
||||
tc.instructions = parsedSet.instructions
|
||||
@@ -668,7 +691,9 @@ func (tc *Context) generatePoolL2Txs() ([]common.PoolL2Tx, error) {
|
||||
tx.Signature = sig.Compress()
|
||||
txs = append(txs, tx)
|
||||
default:
|
||||
return nil, tracerr.Wrap(fmt.Errorf("Line %d: instruction type unrecognized: %s", inst.LineNum, inst.Typ))
|
||||
return nil,
|
||||
tracerr.Wrap(fmt.Errorf("Line %d: instruction type unrecognized: %s",
|
||||
inst.LineNum, inst.Typ))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,49 +119,66 @@ func TestGenerateBlocks(t *testing.T) {
|
||||
|
||||
// Check expected values generated by each line
|
||||
// #0: Deposit(1) A: 10
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[0], common.TxTypeCreateAccountDeposit, 1, "A", "", big.NewInt(10), nil)
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[0], common.TxTypeCreateAccountDeposit, 1,
|
||||
"A", "", big.NewInt(10), nil)
|
||||
// #1: Deposit(2) A: 20
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[1], common.TxTypeCreateAccountDeposit, 2, "A", "", big.NewInt(20), nil)
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[1], common.TxTypeCreateAccountDeposit, 2,
|
||||
"A", "", big.NewInt(20), nil)
|
||||
// // #2: Deposit(1) A: 20
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[2], common.TxTypeCreateAccountDeposit, 1, "B", "", big.NewInt(5), nil)
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[2], common.TxTypeCreateAccountDeposit, 1,
|
||||
"B", "", big.NewInt(5), nil)
|
||||
// // #3: CreateAccountDeposit(1) C: 5
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[3], common.TxTypeCreateAccountDeposit, 1, "C", "", big.NewInt(5), nil)
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[3], common.TxTypeCreateAccountDeposit, 1,
|
||||
"C", "", big.NewInt(5), nil)
|
||||
// // #4: CreateAccountDeposit(1) D: 5
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[4], common.TxTypeCreateAccountDeposit, 1, "D", "", big.NewInt(5), nil)
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[4], common.TxTypeCreateAccountDeposit, 1,
|
||||
"D", "", big.NewInt(5), nil)
|
||||
// #5: Transfer(1) A-B: 6 (1)
|
||||
tc.checkL2TxParams(t, blocks[0].Rollup.Batches[2].L2Txs[0], common.TxTypeTransfer, 1, "A", "B", big.NewInt(6), common.BatchNum(3))
|
||||
tc.checkL2TxParams(t, blocks[0].Rollup.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].Rollup.Batches[2].L2Txs[1], common.TxTypeTransfer, 1, "B", "D", big.NewInt(3), common.BatchNum(3))
|
||||
tc.checkL2TxParams(t, blocks[0].Rollup.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].Rollup.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].Rollup.L1UserTxs[5], common.TxTypeCreateAccountDepositTransfer, 1, "F", "A", big.NewInt(15), big.NewInt(10))
|
||||
tc.checkL2TxParams(t, blocks[0].Rollup.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].Rollup.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].Rollup.L1UserTxs[6], common.TxTypeDepositTransfer, 1, "A", "B", big.NewInt(15), big.NewInt(10))
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.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].Rollup.Batches[3].L2Txs[0], common.TxTypeTransfer, 1, "C", "A", big.NewInt(3), common.BatchNum(4))
|
||||
tc.checkL2TxParams(t, blocks[0].Rollup.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].Rollup.Batches[3].L2Txs[1], common.TxTypeTransfer, 2, "A", "B", big.NewInt(15), common.BatchNum(4))
|
||||
tc.checkL2TxParams(t, blocks[0].Rollup.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].Rollup.L1UserTxs[7], common.TxTypeCreateAccountDeposit, 1, "User0", "", big.NewInt(20), nil)
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[7], common.TxTypeCreateAccountDeposit, 1,
|
||||
"User0", "", big.NewInt(20), nil)
|
||||
// // #14: Deposit(3) User1: 20
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[8], common.TxTypeCreateAccountDeposit, 3, "User1", "", big.NewInt(20), nil)
|
||||
tc.checkL1TxParams(t, blocks[0].Rollup.L1UserTxs[8], common.TxTypeCreateAccountDeposit, 3,
|
||||
"User1", "", big.NewInt(20), nil)
|
||||
// #15: Transfer(1) User0-User1: 15 (1)
|
||||
tc.checkL2TxParams(t, blocks[0].Rollup.Batches[4].L2Txs[0], common.TxTypeTransfer, 1, "User0", "User1", big.NewInt(15), common.BatchNum(5))
|
||||
tc.checkL2TxParams(t, blocks[0].Rollup.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].Rollup.Batches[4].L2Txs[1], common.TxTypeTransfer, 3, "User1", "User0", big.NewInt(15), common.BatchNum(5))
|
||||
tc.checkL2TxParams(t, blocks[0].Rollup.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].Rollup.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].Rollup.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].Rollup.Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6))
|
||||
tc.checkL2TxParams(t, blocks[0].Rollup.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].Rollup.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].Rollup.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, depositAmount, amount *big.Int) {
|
||||
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType,
|
||||
tokenID common.TokenID, from, to string, depositAmount, amount *big.Int) {
|
||||
assert.Equal(t, typ, tx.Type)
|
||||
if tx.FromIdx != common.Idx(0) {
|
||||
assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
|
||||
@@ -179,7 +196,8 @@ 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) {
|
||||
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 {
|
||||
@@ -367,7 +385,9 @@ func TestGenerateErrors(t *testing.T) {
|
||||
`
|
||||
tc := NewContext(0, common.RollupConstMaxL1UserTx)
|
||||
_, err := tc.GenerateBlocks(set)
|
||||
assert.Equal(t, "Line 2: Can not process CreateAccountDeposit: TokenID 1 not registered, last registered TokenID: 0", err.Error())
|
||||
assert.Equal(t,
|
||||
"Line 2: Can not process CreateAccountDeposit: TokenID 1 not registered, "+
|
||||
"last registered TokenID: 0", err.Error())
|
||||
|
||||
// ensure AddToken sequentiality and not using 0
|
||||
set = `
|
||||
@@ -384,7 +404,8 @@ func TestGenerateErrors(t *testing.T) {
|
||||
`
|
||||
tc = NewContext(0, common.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(set)
|
||||
require.Equal(t, "Line 2: AddToken TokenID should be sequential, expected TokenID: 1, defined TokenID: 2", err.Error())
|
||||
require.Equal(t, "Line 2: AddToken TokenID should be sequential, expected TokenID: "+
|
||||
"1, defined TokenID: 2", err.Error())
|
||||
|
||||
set = `
|
||||
Type: Blockchain
|
||||
@@ -395,7 +416,8 @@ func TestGenerateErrors(t *testing.T) {
|
||||
`
|
||||
tc = NewContext(0, common.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(set)
|
||||
require.Equal(t, "Line 5: AddToken TokenID should be sequential, expected TokenID: 4, defined TokenID: 5", err.Error())
|
||||
require.Equal(t, "Line 5: AddToken TokenID should be sequential, expected TokenID: "+
|
||||
"4, defined TokenID: 5", err.Error())
|
||||
|
||||
// check transactions when account is not created yet
|
||||
set = `
|
||||
@@ -409,7 +431,8 @@ func TestGenerateErrors(t *testing.T) {
|
||||
`
|
||||
tc = NewContext(0, common.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(set)
|
||||
require.Equal(t, "Line 5: CreateAccountDeposit(1)BTransfer(1) A-B: 6 (1)\n, err: Expected ':', found 'Transfer'", err.Error())
|
||||
require.Equal(t, "Line 5: CreateAccountDeposit(1)BTransfer(1) A-B: 6 (1)\n, err: "+
|
||||
"Expected ':', found 'Transfer'", err.Error())
|
||||
set = `
|
||||
Type: Blockchain
|
||||
AddToken(1)
|
||||
@@ -434,7 +457,8 @@ func TestGenerateErrors(t *testing.T) {
|
||||
CreateAccountCoordinator(1) B
|
||||
> batchL1
|
||||
Transfer(1) A-B: 6 (1)
|
||||
Transfer(1) A-B: 6 (1) // on purpose this is moving more money that what it has in the account, Til should not fail
|
||||
Transfer(1) A-B: 6 (1) // on purpose this is moving more money that
|
||||
// what it has in the account, Til should not fail
|
||||
Transfer(1) B-A: 6 (1)
|
||||
Exit(1) A: 3 (1)
|
||||
> batch
|
||||
@@ -558,7 +582,8 @@ func TestGenerateFromInstructions(t *testing.T) {
|
||||
CreateAccountCoordinator(1) B
|
||||
> batchL1
|
||||
Transfer(1) A-B: 6 (1)
|
||||
Transfer(1) A-B: 6 (1) // on purpose this is moving more money that what it has in the account, Til should not fail
|
||||
Transfer(1) A-B: 6 (1) // on purpose this is moving more money that
|
||||
// what it has in the account, Til should not fail
|
||||
Transfer(1) B-A: 6 (1)
|
||||
Exit(1) A: 3 (1)
|
||||
> batch
|
||||
|
||||
Reference in New Issue
Block a user