mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Update missing parts, improve til, and more
- Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
This commit is contained in:
@@ -60,11 +60,11 @@ func GenBatches(nBatches int, blocks []common.Block) []common.Batch {
|
||||
//nolint:gomnd
|
||||
ForgerAddr: ethCommon.BigToAddress(big.NewInt(6886723)),
|
||||
CollectedFees: collectedFees,
|
||||
StateRoot: common.Hash([]byte("duhdqlwiucgwqeiu")),
|
||||
StateRoot: big.NewInt(int64(i) * 5), //nolint:gomnd
|
||||
//nolint:gomnd
|
||||
NumAccounts: 30,
|
||||
ExitRoot: common.Hash([]byte("tykertheuhtgenuer3iuw3b")),
|
||||
SlotNum: common.SlotNum(i),
|
||||
ExitRoot: big.NewInt(int64(i) * 16), //nolint:gomnd
|
||||
SlotNum: int64(i),
|
||||
}
|
||||
if i%2 == 0 {
|
||||
toForge := new(int64)
|
||||
@@ -324,7 +324,7 @@ func GenBids(nBids int, blocks []common.Block, coords []common.Coordinator) []co
|
||||
bids := []common.Bid{}
|
||||
for i := 0; i < nBids; i++ {
|
||||
bids = append(bids, common.Bid{
|
||||
SlotNum: common.SlotNum(i),
|
||||
SlotNum: int64(i),
|
||||
BidValue: big.NewInt(int64(i)),
|
||||
EthBlockNum: blocks[i%len(blocks)].EthBlockNum,
|
||||
Bidder: coords[i%len(blocks)].Bidder,
|
||||
|
||||
@@ -18,8 +18,8 @@ Available instructions:
|
||||
```go
|
||||
Type: Blockchain
|
||||
|
||||
// register the TokenID:
|
||||
RegisterToken(1)
|
||||
// add the TokenID:
|
||||
AddToken(1)
|
||||
|
||||
// deposit of TokenID=1, on the account of tokenID=1 for the user A, of an
|
||||
// amount of 50 units
|
||||
|
||||
@@ -39,10 +39,10 @@ var typeNewBatchL1 common.TxType = "InstrTypeNewBatchL1"
|
||||
// common.TxType of a new ethereum block
|
||||
var typeNewBlock common.TxType = "InstrTypeNewBlock"
|
||||
|
||||
// typeRegisterToken is used for testing purposes only, and represents the
|
||||
// typeAddToken is used for testing purposes only, and represents the
|
||||
// common.TxType of a new Token regsitration
|
||||
// It has 'nolint:gosec' as the string 'Token' triggers gosec as a potential leaked Token (which is not the case)
|
||||
var typeRegisterToken common.TxType = "InstrTypeRegisterToken" //nolint:gosec
|
||||
var typeAddToken common.TxType = "InstrTypeAddToken" //nolint:gosec
|
||||
|
||||
var txTypeCreateAccountDepositCoordinator common.TxType = "TypeCreateAccountDepositCoordinator"
|
||||
|
||||
@@ -306,7 +306,7 @@ func (p *parser) parseLine(setType setType) (*instruction, error) {
|
||||
} else {
|
||||
return c, fmt.Errorf("Invalid set type: '%s'. Valid set types: 'Blockchain', 'PoolL2'", lit)
|
||||
}
|
||||
} else if lit == "RegisterToken" {
|
||||
} else if lit == "AddToken" {
|
||||
if err := p.expectChar(c, "("); err != nil {
|
||||
return c, err
|
||||
}
|
||||
@@ -322,7 +322,7 @@ func (p *parser) parseLine(setType setType) (*instruction, error) {
|
||||
if err := p.expectChar(c, ")"); err != nil {
|
||||
return c, err
|
||||
}
|
||||
c.typ = typeRegisterToken
|
||||
c.typ = typeAddToken
|
||||
line, _ := p.s.r.ReadString('\n')
|
||||
c.literal += line
|
||||
return c, newEventLine
|
||||
@@ -519,8 +519,8 @@ func (p *parser) parse() (*parsedSet, error) {
|
||||
}
|
||||
instruction.lineNum = i
|
||||
if err == newEventLine {
|
||||
if instruction.typ == typeRegisterToken && instruction.tokenID == common.TokenID(0) {
|
||||
return ps, fmt.Errorf("Line %d: RegisterToken can not register TokenID 0", i)
|
||||
if instruction.typ == typeAddToken && instruction.tokenID == common.TokenID(0) {
|
||||
return ps, fmt.Errorf("Line %d: AddToken can not register TokenID 0", i)
|
||||
}
|
||||
ps.instructions = append(ps.instructions, *instruction)
|
||||
continue
|
||||
|
||||
@@ -16,8 +16,8 @@ func TestParseBlockchainTxs(t *testing.T) {
|
||||
Type: Blockchain
|
||||
|
||||
// token registrations
|
||||
RegisterToken(1)
|
||||
RegisterToken(2)
|
||||
AddToken(1)
|
||||
AddToken(2)
|
||||
|
||||
// deposits
|
||||
Deposit(1) A: 10
|
||||
@@ -34,7 +34,7 @@ func TestParseBlockchainTxs(t *testing.T) {
|
||||
|
||||
// set new batch
|
||||
> batch
|
||||
RegisterToken(3)
|
||||
AddToken(3)
|
||||
|
||||
DepositTransfer(1) A-B: 15, 10 (1)
|
||||
Transfer(1) C-A : 3 (1)
|
||||
@@ -121,7 +121,7 @@ func TestParseErrors(t *testing.T) {
|
||||
|
||||
s = `
|
||||
Type: Blockchain
|
||||
RegisterToken(1)
|
||||
AddToken(1)
|
||||
Deposit(1) A: 10 20
|
||||
`
|
||||
parser = newParser(strings.NewReader(s))
|
||||
@@ -146,7 +146,7 @@ func TestParseErrors(t *testing.T) {
|
||||
|
||||
s = `
|
||||
Type: Blockchain
|
||||
RegisterToken(1)
|
||||
AddToken(1)
|
||||
Transfer(1) A-B: 10 (255)
|
||||
`
|
||||
parser = newParser(strings.NewReader(s))
|
||||
@@ -206,10 +206,10 @@ func TestParseErrors(t *testing.T) {
|
||||
assert.Equal(t, "Line 2: Instruction of 'Type: Blockchain' when there is already a previous instruction 'Type: PoolL2' defined", err.Error())
|
||||
|
||||
s = `Type: Blockchain
|
||||
RegisterToken(1)
|
||||
RegisterToken(0)
|
||||
AddToken(1)
|
||||
AddToken(0)
|
||||
`
|
||||
parser = newParser(strings.NewReader(s))
|
||||
_, err = parser.parse()
|
||||
assert.Equal(t, "Line 3: RegisterToken can not register TokenID 0", err.Error())
|
||||
assert.Equal(t, "Line 3: AddToken can not register TokenID 0", err.Error())
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ package til
|
||||
var SetBlockchain0 = `
|
||||
// Set containing Blockchain transactions
|
||||
Type: Blockchain
|
||||
RegisterToken(1)
|
||||
RegisterToken(2)
|
||||
RegisterToken(3)
|
||||
AddToken(1)
|
||||
AddToken(2)
|
||||
AddToken(3)
|
||||
|
||||
// deposits TokenID: 1
|
||||
CreateAccountDeposit(1) A: 50
|
||||
|
||||
@@ -26,17 +26,22 @@ type Context struct {
|
||||
// rollupConstMaxL1UserTx Maximum L1-user transactions allowed to be queued in a batch
|
||||
rollupConstMaxL1UserTx int
|
||||
|
||||
idx int
|
||||
currBlock BlockData
|
||||
currBatch BatchData
|
||||
currBatchNum int
|
||||
queues [][]L1Tx
|
||||
toForgeNum int
|
||||
openToForge int
|
||||
idx int
|
||||
currBlock common.BlockData
|
||||
currBatch common.BatchData
|
||||
currBatchNum int
|
||||
queues [][]L1Tx
|
||||
toForgeNum int
|
||||
openToForge int
|
||||
currBatchTest struct {
|
||||
l1CoordinatorTxs []L1Tx
|
||||
l2Txs []L2Tx
|
||||
}
|
||||
}
|
||||
|
||||
// NewContext returns a new Context
|
||||
func NewContext(rollupConstMaxL1UserTx int) *Context {
|
||||
currBatchNum := 1 // The protocol defines the first batchNum to be 1
|
||||
return &Context{
|
||||
Users: make(map[string]*User),
|
||||
l1CreatedAccounts: make(map[string]*Account),
|
||||
@@ -44,7 +49,12 @@ func NewContext(rollupConstMaxL1UserTx int) *Context {
|
||||
|
||||
rollupConstMaxL1UserTx: rollupConstMaxL1UserTx,
|
||||
idx: common.UserThreshold,
|
||||
currBatchNum: 0,
|
||||
// We use some placeholder values for StateRoot and ExitTree
|
||||
// because these values will never be nil
|
||||
currBatch: common.BatchData{Batch: common.Batch{
|
||||
BatchNum: common.BatchNum(currBatchNum),
|
||||
StateRoot: big.NewInt(0), ExitRoot: big.NewInt(0)}},
|
||||
currBatchNum: currBatchNum,
|
||||
// start with 2 queues, one for toForge, and the other for openToForge
|
||||
queues: make([][]L1Tx, 2),
|
||||
toForgeNum: 0,
|
||||
@@ -65,26 +75,6 @@ type User struct {
|
||||
Accounts map[common.TokenID]*Account
|
||||
}
|
||||
|
||||
// BlockData contains the information of a Block
|
||||
type BlockData struct {
|
||||
// block *common.Block // ethereum block
|
||||
// L1UserTxs that were accepted in the block
|
||||
L1UserTxs []common.L1Tx
|
||||
Batches []BatchData
|
||||
RegisteredTokens []common.Token
|
||||
}
|
||||
|
||||
// BatchData contains the information of a Batch
|
||||
type BatchData struct {
|
||||
L1Batch bool // TODO: Remove once Batch.ForgeL1TxsNum is a pointer
|
||||
L1CoordinatorTxs []common.L1Tx
|
||||
testL1CoordinatorTxs []L1Tx
|
||||
L2Txs []common.L2Tx
|
||||
// testL2Tx are L2Txs without the Idx&EthAddr&BJJ setted, but with the
|
||||
// string that represents the account
|
||||
testL2Txs []L2Tx
|
||||
}
|
||||
|
||||
// L1Tx is the data structure used internally for transaction test generation,
|
||||
// which contains a common.L1Tx data plus some intermediate data for the
|
||||
// transaction generation.
|
||||
@@ -109,7 +99,7 @@ type L2Tx struct {
|
||||
|
||||
// GenerateBlocks returns an array of BlockData for a given set. It uses the
|
||||
// accounts (keys & nonces) of the Context.
|
||||
func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) {
|
||||
parser := newParser(strings.NewReader(set))
|
||||
parsedSet, err := parser.parse()
|
||||
if err != nil {
|
||||
@@ -121,7 +111,7 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
|
||||
tc.generateKeys(tc.accountsNames)
|
||||
|
||||
var blocks []BlockData
|
||||
var blocks []common.BlockData
|
||||
for _, inst := range parsedSet.instructions {
|
||||
switch inst.typ {
|
||||
case txTypeCreateAccountDepositCoordinator:
|
||||
@@ -133,6 +123,7 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
FromEthAddr: tc.Users[inst.from].Addr,
|
||||
FromBJJ: tc.Users[inst.from].BJJ.Public(),
|
||||
TokenID: inst.tokenID,
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: big.NewInt(int64(inst.loadAmount)),
|
||||
Type: common.TxTypeCreateAccountDeposit, // as txTypeCreateAccountDepositCoordinator is not valid oustide Til package
|
||||
}
|
||||
@@ -141,7 +132,7 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
fromIdxName: inst.from,
|
||||
L1Tx: tx,
|
||||
}
|
||||
tc.currBatch.testL1CoordinatorTxs = append(tc.currBatch.testL1CoordinatorTxs, testTx)
|
||||
tc.currBatchTest.l1CoordinatorTxs = append(tc.currBatchTest.l1CoordinatorTxs, testTx)
|
||||
case common.TxTypeCreateAccountDeposit, common.TxTypeCreateAccountDepositTransfer:
|
||||
if err := tc.checkIfTokenIsRegistered(inst); err != nil {
|
||||
log.Error(err)
|
||||
@@ -151,6 +142,7 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
FromEthAddr: tc.Users[inst.from].Addr,
|
||||
FromBJJ: tc.Users[inst.from].BJJ.Public(),
|
||||
TokenID: inst.tokenID,
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: big.NewInt(int64(inst.loadAmount)),
|
||||
Type: inst.typ,
|
||||
}
|
||||
@@ -175,6 +167,7 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
}
|
||||
tx := common.L1Tx{
|
||||
TokenID: inst.tokenID,
|
||||
Amount: big.NewInt(0),
|
||||
LoadAmount: big.NewInt(int64(inst.loadAmount)),
|
||||
Type: inst.typ,
|
||||
}
|
||||
@@ -206,7 +199,7 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
tokenID: inst.tokenID,
|
||||
L2Tx: tx,
|
||||
}
|
||||
tc.currBatch.testL2Txs = append(tc.currBatch.testL2Txs, testTx)
|
||||
tc.currBatchTest.l2Txs = append(tc.currBatchTest.l2Txs, testTx)
|
||||
case common.TxTypeExit:
|
||||
if err := tc.checkIfTokenIsRegistered(inst); err != nil {
|
||||
log.Error(err)
|
||||
@@ -225,17 +218,18 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
tokenID: inst.tokenID,
|
||||
L2Tx: tx,
|
||||
}
|
||||
tc.currBatch.testL2Txs = append(tc.currBatch.testL2Txs, testTx)
|
||||
tc.currBatchTest.l2Txs = append(tc.currBatchTest.l2Txs, testTx)
|
||||
case common.TxTypeForceExit:
|
||||
if err := tc.checkIfTokenIsRegistered(inst); err != nil {
|
||||
log.Error(err)
|
||||
return nil, fmt.Errorf("Line %d: %s", inst.lineNum, err.Error())
|
||||
}
|
||||
tx := common.L1Tx{
|
||||
ToIdx: common.Idx(1), // as is an Exit
|
||||
TokenID: inst.tokenID,
|
||||
Amount: big.NewInt(int64(inst.amount)),
|
||||
Type: common.TxTypeExit,
|
||||
ToIdx: common.Idx(1), // as is an Exit
|
||||
TokenID: inst.tokenID,
|
||||
Amount: big.NewInt(int64(inst.amount)),
|
||||
LoadAmount: big.NewInt(0),
|
||||
Type: common.TxTypeExit,
|
||||
}
|
||||
testTx := L1Tx{
|
||||
lineNum: inst.lineNum,
|
||||
@@ -245,7 +239,7 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
}
|
||||
tc.addToL1Queue(testTx)
|
||||
case typeNewBatch:
|
||||
if err = tc.calculateIdxForL1Txs(true, tc.currBatch.testL1CoordinatorTxs); err != nil {
|
||||
if err = tc.calculateIdxForL1Txs(true, tc.currBatchTest.l1CoordinatorTxs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = tc.setIdxs(); err != nil {
|
||||
@@ -257,7 +251,7 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
if err = tc.calculateIdxForL1Txs(false, tc.queues[tc.toForgeNum]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = tc.calculateIdxForL1Txs(true, tc.currBatch.testL1CoordinatorTxs); err != nil {
|
||||
if err = tc.calculateIdxForL1Txs(true, tc.currBatchTest.l1CoordinatorTxs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -277,8 +271,8 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
if testTx.L1Tx.Type == common.TxTypeExit {
|
||||
testTx.L1Tx.ToIdx = common.Idx(1)
|
||||
}
|
||||
bn := common.BatchNum(tc.currBatchNum)
|
||||
testTx.L1Tx.BatchNum = &bn
|
||||
// bn := common.BatchNum(tc.currBatchNum)
|
||||
// testTx.L1Tx.BatchNum = &bn
|
||||
nTx, err := common.NewL1Tx(&testTx.L1Tx)
|
||||
if err != nil {
|
||||
fmt.Println(testTx)
|
||||
@@ -301,17 +295,17 @@ func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
|
||||
}
|
||||
case typeNewBlock:
|
||||
blocks = append(blocks, tc.currBlock)
|
||||
tc.currBlock = BlockData{}
|
||||
case typeRegisterToken:
|
||||
tc.currBlock = common.BlockData{}
|
||||
case typeAddToken:
|
||||
newToken := common.Token{
|
||||
TokenID: inst.tokenID,
|
||||
EthBlockNum: int64(len(blocks)),
|
||||
}
|
||||
if inst.tokenID != tc.lastRegisteredTokenID+1 {
|
||||
return nil, fmt.Errorf("Line %d: RegisterToken TokenID should be sequential, expected TokenID: %d, defined TokenID: %d", inst.lineNum, tc.lastRegisteredTokenID+1, inst.tokenID)
|
||||
return nil, 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.RegisteredTokens = append(tc.currBlock.RegisteredTokens, newToken)
|
||||
tc.currBlock.AddedTokens = append(tc.currBlock.AddedTokens, newToken)
|
||||
default:
|
||||
return nil, fmt.Errorf("Line %d: Unexpected type: %s", inst.lineNum, inst.typ)
|
||||
}
|
||||
@@ -347,8 +341,8 @@ func (tc *Context) calculateIdxForL1Txs(isCoordinatorTxs bool, txs []L1Tx) error
|
||||
// setIdxs sets the Idxs to the transactions of the tc.currBatch
|
||||
func (tc *Context) setIdxs() error {
|
||||
// once Idxs are calculated, update transactions to use the new Idxs
|
||||
for i := 0; i < len(tc.currBatch.testL2Txs); i++ {
|
||||
testTx := &tc.currBatch.testL2Txs[i]
|
||||
for i := 0; i < len(tc.currBatchTest.l2Txs); i++ {
|
||||
testTx := &tc.currBatchTest.l2Txs[i]
|
||||
|
||||
if tc.Users[testTx.fromIdxName].Accounts[testTx.tokenID] == nil {
|
||||
return 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)
|
||||
@@ -380,8 +374,10 @@ func (tc *Context) setIdxs() error {
|
||||
|
||||
tc.currBlock.Batches = append(tc.currBlock.Batches, tc.currBatch)
|
||||
tc.currBatchNum++
|
||||
tc.currBatch = BatchData{}
|
||||
|
||||
tc.currBatch = common.BatchData{Batch: tc.currBatch.Batch}
|
||||
tc.currBatch.Batch.BatchNum = common.BatchNum(tc.currBatchNum)
|
||||
tc.currBatchTest.l1CoordinatorTxs = nil
|
||||
tc.currBatchTest.l2Txs = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -394,6 +390,9 @@ func (tc *Context) addToL1Queue(tx L1Tx) {
|
||||
newQueue := []L1Tx{}
|
||||
tc.queues = append(tc.queues, newQueue)
|
||||
}
|
||||
tx.L1Tx.UserOrigin = true
|
||||
toForgeL1TxsNum := int64(tc.openToForge)
|
||||
tx.L1Tx.ToForgeL1TxsNum = &toForgeL1TxsNum
|
||||
tc.queues[tc.openToForge] = append(tc.queues[tc.openToForge], tx)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ import (
|
||||
func TestGenerateBlocks(t *testing.T) {
|
||||
set := `
|
||||
Type: Blockchain
|
||||
RegisterToken(1)
|
||||
RegisterToken(2)
|
||||
RegisterToken(3)
|
||||
AddToken(1)
|
||||
AddToken(2)
|
||||
AddToken(3)
|
||||
|
||||
CreateAccountDeposit(1) A: 10
|
||||
CreateAccountDeposit(2) A: 20
|
||||
@@ -23,15 +23,15 @@ func TestGenerateBlocks(t *testing.T) {
|
||||
CreateAccountDeposit(1) C: 5
|
||||
CreateAccountDepositTransfer(1) D-A: 15, 10 (3)
|
||||
|
||||
> batchL1
|
||||
> batchL1
|
||||
> batchL1 // batchNum = 1
|
||||
> batchL1 // batchNum = 2
|
||||
|
||||
Transfer(1) A-B: 6 (1)
|
||||
Transfer(1) B-D: 3 (1)
|
||||
Transfer(1) A-D: 1 (1)
|
||||
|
||||
// set new batch
|
||||
> batch
|
||||
> batch // batchNum = 3
|
||||
CreateAccountDepositCoordinator(1) E
|
||||
CreateAccountDepositCoordinator(2) B
|
||||
|
||||
@@ -44,12 +44,12 @@ func TestGenerateBlocks(t *testing.T) {
|
||||
CreateAccountDeposit(3) User1: 20
|
||||
CreateAccountDepositCoordinator(1) User1
|
||||
CreateAccountDepositCoordinator(3) User0
|
||||
> batchL1
|
||||
> batchL1 // batchNum = 4
|
||||
Transfer(1) User0-User1: 15 (1)
|
||||
Transfer(3) User1-User0: 15 (1)
|
||||
Transfer(1) A-C: 1 (1)
|
||||
|
||||
> batchL1
|
||||
> batchL1 // batchNum = 5
|
||||
|
||||
Transfer(1) User1-User0: 1 (1)
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestGenerateBlocks(t *testing.T) {
|
||||
Transfer(1) A-B: 1 (1)
|
||||
Exit(1) A: 5
|
||||
|
||||
> batch
|
||||
> batch // batchNum = 6
|
||||
> block
|
||||
|
||||
// this transaction should not be generated, as it's after last
|
||||
@@ -88,34 +88,34 @@ func TestGenerateBlocks(t *testing.T) {
|
||||
// // #4: CreateAccountDepositTransfer(1) D-A: 15, 10 (3)
|
||||
tc.checkL1TxParams(t, blocks[0].L1UserTxs[4], common.TxTypeCreateAccountDepositTransfer, 1, "D", "A", big.NewInt(15), big.NewInt(10))
|
||||
// #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(2), common.Nonce(1))
|
||||
tc.checkL2TxParams(t, blocks[0].Batches[2].L2Txs[0], common.TxTypeTransfer, 1, "A", "B", big.NewInt(6), common.BatchNum(3), common.Nonce(1))
|
||||
// #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(2), common.Nonce(1))
|
||||
tc.checkL2TxParams(t, blocks[0].Batches[2].L2Txs[1], common.TxTypeTransfer, 1, "B", "D", big.NewInt(3), common.BatchNum(3), common.Nonce(1))
|
||||
// #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(2), common.Nonce(2))
|
||||
tc.checkL2TxParams(t, blocks[0].Batches[2].L2Txs[2], common.TxTypeTransfer, 1, "A", "D", big.NewInt(1), common.BatchNum(3), common.Nonce(2))
|
||||
// change of Batch
|
||||
// #8: DepositTransfer(1) A-B: 15, 10 (1)
|
||||
tc.checkL1TxParams(t, blocks[0].L1UserTxs[5], common.TxTypeDepositTransfer, 1, "A", "B", big.NewInt(15), big.NewInt(10))
|
||||
// #10: 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(3), common.Nonce(1))
|
||||
tc.checkL2TxParams(t, blocks[0].Batches[3].L2Txs[0], common.TxTypeTransfer, 1, "C", "A", big.NewInt(3), common.BatchNum(4), common.Nonce(1))
|
||||
// #11: 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(3), common.Nonce(1))
|
||||
tc.checkL2TxParams(t, blocks[0].Batches[3].L2Txs[1], common.TxTypeTransfer, 2, "A", "B", big.NewInt(15), common.BatchNum(4), common.Nonce(1))
|
||||
// #12: Deposit(1) User0: 20
|
||||
tc.checkL1TxParams(t, blocks[0].L1UserTxs[6], common.TxTypeCreateAccountDeposit, 1, "User0", "", big.NewInt(20), nil)
|
||||
// // #13: Deposit(3) User1: 20
|
||||
tc.checkL1TxParams(t, blocks[0].L1UserTxs[7], common.TxTypeCreateAccountDeposit, 3, "User1", "", big.NewInt(20), nil)
|
||||
// #14: 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(4), common.Nonce(1))
|
||||
tc.checkL2TxParams(t, blocks[0].Batches[4].L2Txs[0], common.TxTypeTransfer, 1, "User0", "User1", big.NewInt(15), common.BatchNum(5), common.Nonce(1))
|
||||
// #15: 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(4), common.Nonce(1))
|
||||
tc.checkL2TxParams(t, blocks[0].Batches[4].L2Txs[1], common.TxTypeTransfer, 3, "User1", "User0", big.NewInt(15), common.BatchNum(5), common.Nonce(1))
|
||||
// #16: 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(4), common.Nonce(4))
|
||||
tc.checkL2TxParams(t, blocks[0].Batches[4].L2Txs[2], common.TxTypeTransfer, 1, "A", "C", big.NewInt(1), common.BatchNum(5), common.Nonce(4))
|
||||
// change of Batch
|
||||
// #17: 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(5), common.Nonce(1))
|
||||
tc.checkL2TxParams(t, blocks[1].Batches[0].L2Txs[0], common.TxTypeTransfer, 1, "User1", "User0", big.NewInt(1), common.BatchNum(6), common.Nonce(1))
|
||||
// change of Block (implies also a change of batch)
|
||||
// #18: 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(5), common.Nonce(5))
|
||||
tc.checkL2TxParams(t, blocks[1].Batches[0].L2Txs[1], common.TxTypeTransfer, 1, "A", "B", big.NewInt(1), common.BatchNum(6), common.Nonce(5))
|
||||
}
|
||||
|
||||
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, loadAmount, amount *big.Int) {
|
||||
@@ -151,9 +151,9 @@ func (tc *Context) checkL2TxParams(t *testing.T, tx common.L2Tx, typ common.TxTy
|
||||
func TestGeneratePoolL2Txs(t *testing.T) {
|
||||
set := `
|
||||
Type: Blockchain
|
||||
RegisterToken(1)
|
||||
RegisterToken(2)
|
||||
RegisterToken(3)
|
||||
AddToken(1)
|
||||
AddToken(2)
|
||||
AddToken(3)
|
||||
|
||||
CreateAccountDeposit(1) A: 10
|
||||
CreateAccountDeposit(2) A: 20
|
||||
@@ -221,38 +221,38 @@ func TestGenerateErrors(t *testing.T) {
|
||||
_, err := tc.GenerateBlocks(set)
|
||||
assert.Equal(t, "Line 2: Can not process CreateAccountDeposit: TokenID 1 not registered, last registered TokenID: 0", err.Error())
|
||||
|
||||
// ensure RegisterToken sequentiality and not using 0
|
||||
// ensure AddToken sequentiality and not using 0
|
||||
set = `
|
||||
Type: Blockchain
|
||||
RegisterToken(0)
|
||||
AddToken(0)
|
||||
`
|
||||
tc = NewContext(eth.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(set)
|
||||
require.Equal(t, "Line 2: RegisterToken can not register TokenID 0", err.Error())
|
||||
require.Equal(t, "Line 2: AddToken can not register TokenID 0", err.Error())
|
||||
|
||||
set = `
|
||||
Type: Blockchain
|
||||
RegisterToken(2)
|
||||
AddToken(2)
|
||||
`
|
||||
tc = NewContext(eth.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(set)
|
||||
require.Equal(t, "Line 2: RegisterToken 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
|
||||
RegisterToken(1)
|
||||
RegisterToken(2)
|
||||
RegisterToken(3)
|
||||
RegisterToken(5)
|
||||
AddToken(1)
|
||||
AddToken(2)
|
||||
AddToken(3)
|
||||
AddToken(5)
|
||||
`
|
||||
tc = NewContext(eth.RollupConstMaxL1UserTx)
|
||||
_, err = tc.GenerateBlocks(set)
|
||||
require.Equal(t, "Line 5: RegisterToken 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 = `
|
||||
Type: Blockchain
|
||||
RegisterToken(1)
|
||||
AddToken(1)
|
||||
CreateAccountDeposit(1) A: 10
|
||||
> batchL1
|
||||
CreateAccountDeposit(1) B
|
||||
@@ -264,7 +264,7 @@ func TestGenerateErrors(t *testing.T) {
|
||||
require.Equal(t, "Line 5: CreateAccountDeposit(1)BTransfer(1) A-B: 6 (1)\n, err: Expected ':', found 'Transfer'", err.Error())
|
||||
set = `
|
||||
Type: Blockchain
|
||||
RegisterToken(1)
|
||||
AddToken(1)
|
||||
CreateAccountDeposit(1) A: 10
|
||||
> batchL1
|
||||
CreateAccountDepositCoordinator(1) B
|
||||
@@ -280,7 +280,7 @@ func TestGenerateErrors(t *testing.T) {
|
||||
// check nonces
|
||||
set = `
|
||||
Type: Blockchain
|
||||
RegisterToken(1)
|
||||
AddToken(1)
|
||||
CreateAccountDeposit(1) A: 10
|
||||
> batchL1
|
||||
CreateAccountDepositCoordinator(1) B
|
||||
|
||||
Reference in New Issue
Block a user