Browse Source

Rename Transakcio to Til for a easier usage

Rename Transakcio to Til for a easier usage, also change til.TestContext
to til.Context, and til.NewTestContext to til.NewContext.
feature/sql-semaphore1
arnaucube 4 years ago
parent
commit
265bdf23e3
11 changed files with 166 additions and 60 deletions
  1. +7
    -7
      db/statedb/txprocessors_test.go
  2. +1
    -1
      synchronizer/synchronizer_test.go
  3. +115
    -0
      test/til/README.md
  4. +1
    -1
      test/til/lang.go
  5. +1
    -1
      test/til/lang_test.go
  6. +1
    -1
      test/til/sets.go
  7. +2
    -2
      test/til/sets_test.go
  8. +22
    -22
      test/til/txs.go
  9. +14
    -14
      test/til/txs_test.go
  10. +0
    -9
      test/transakcio/utils.go
  11. +2
    -2
      txselector/txselector_test.go

+ 7
- 7
db/statedb/txprocessors_test.go

@ -7,7 +7,7 @@ import (
"github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/common"
"github.com/hermeznetwork/hermez-node/eth" "github.com/hermeznetwork/hermez-node/eth"
"github.com/hermeznetwork/hermez-node/test/transakcio"
"github.com/hermeznetwork/hermez-node/test/til"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -24,8 +24,8 @@ func TestProcessTxsSynchronizer(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
// generate test transactions from test.SetTest0 code // generate test transactions from test.SetTest0 code
tc := transakcio.NewTestContext(eth.RollupConstMaxL1UserTx)
blocks, err := tc.GenerateBlocks(transakcio.SetBlockchain0)
tc := til.NewContext(eth.RollupConstMaxL1UserTx)
blocks, err := tc.GenerateBlocks(til.SetBlockchain0)
require.Nil(t, err) require.Nil(t, err)
assert.Equal(t, 29, len(blocks[0].L1UserTxs)) assert.Equal(t, 29, len(blocks[0].L1UserTxs))
@ -89,8 +89,8 @@ func TestProcessTxsBatchBuilder(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
// generate test transactions from test.SetTest0 code // generate test transactions from test.SetTest0 code
tc := transakcio.NewTestContext()
blocks := tc.GenerateBlocks(transakcio.SetBlockchain0)
tc := til.NewContext()
blocks := tc.GenerateBlocks(til.SetBlockchain0)
assert.Equal(t, 29, len(blocks[0].Batches[0].L1UserTxs)) assert.Equal(t, 29, len(blocks[0].Batches[0].L1UserTxs))
assert.Equal(t, 0, len(blocks[0].Batches[0].L1CoordinatorTxs)) assert.Equal(t, 0, len(blocks[0].Batches[0].L1CoordinatorTxs))
@ -139,8 +139,8 @@ func TestZKInputsGeneration(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
// generate test transactions from test.SetTest0 code // generate test transactions from test.SetTest0 code
tc := transakcio.NewTestContext()
blocks := tc.GenerateBlocks(transakcio.SetBlockchain0)
tc := til.NewContext()
blocks := tc.GenerateBlocks(til.SetBlockchain0)
assert.Equal(t, 29, len(blocks[0].Batches[0].L1UserTxs)) assert.Equal(t, 29, len(blocks[0].Batches[0].L1UserTxs))
assert.Equal(t, 0, len(blocks[0].Batches[0].L1CoordinatorTxs)) assert.Equal(t, 0, len(blocks[0].Batches[0].L1CoordinatorTxs))
assert.Equal(t, 21, len(blocks[0].Batches[0].L2Txs)) assert.Equal(t, 21, len(blocks[0].Batches[0].L2Txs))

+ 1
- 1
synchronizer/synchronizer_test.go

@ -60,7 +60,7 @@ func TestSync(t *testing.T) {
require.Nil(t, err) require.Nil(t, err)
assert.Equal(t, int64(1), blocks[0].EthBlockNum) assert.Equal(t, int64(1), blocks[0].EthBlockNum)
// TODO once transakcio is completed
// TODO once Til is completed
/* /*
// Test Sync for a block with new Tokens and L1UserTxs // Test Sync for a block with new Tokens and L1UserTxs
// accounts := test.GenerateKeys(t, []string{"A", "B", "C", "D"}) // accounts := test.GenerateKeys(t, []string{"A", "B", "C", "D"})

+ 115
- 0
test/til/README.md

@ -0,0 +1,115 @@
# Til (Test instructions language)
Language to define sets of instructions to simulate Hermez transactions (L1 & L2) with real data.
## Syntax
### Global
- Set type definition
- Blockchain: generate the transactions that would come from the Hermez smart contract on the blockchain.
```
Type: Blockchain
```
- PoolL2: generate the transactions that would come from the Pool of L2Txs
```
Type: PoolL2
```
### Blockchain set of instructions
Available instructions:
```go
Type: Blockchain
// register the TokenID:
RegisterToken(1)
// deposit of TokenID=1, on the account of tokenID=1 for the user A, of an
// amount of 50 units
CreateAccountDeposit(1) A: 50
// create the account of TokenID=1 for the user B, deposit of TokenID=1, on the
// account of tokenID=1 for the user B, of an amount of 40 units and atomically
// transfer 10 units to account of tokenID=1 for the user A, paying a fee of 2
CreateAccountDepositTransfer(1) B-A: 40, 10 (2)
// transaction generated by the Coordinator, create account for user User0 for
// the TokenID=2, with a deposit of 0
CreateAccountDepositCoordinator(2) User0
// deposit of TokenID=1, at the account A, of 6 units
Deposit(1) A: 6
// deposit of TokenID=1, on the account of tokenID=1 for the user B, of an
// amount of 6 units and atomically transfer 10 units to account of tokenID=1 for
// the user A, paying a fee of 2
DepositTransfer(1) B-A: 6, 4 (2)
// transfer of TokenID=1, from the account A to B (for that token), of 6 units,
// paying a fee of 3. Transaction will be a L2Tx
Transfer(1) A-B: 6 (3)
// exit of TokenID=1, from the account A (for that token), of 5 units.
// Transaction will be a L2Tx
Exit(1) A: 5
// force-transfer of TokenID=1, from the account A to B (for that token), of 6
// units, paying a fee of 3. Transaction will be L1UserTx of ForceTransfer type
ForceTransfer(1) A-B: 6 (3)
// force-exit of TokenID=1, from the account A (for that token), of 5 units.
// Transaction will be L1UserTx of ForceExit type
ForceExit(1) A: 5
// advance one batch, forging without L1UserTxs, only can contain L2Txs and
// L1CoordinatorTxs
> batch
// advance one batch, forging with L1UserTxs (and L2Txs and L1CoordinatorTxs)
> batchL1
// advance an ethereum block
> block
```
### PoolL2 set of instructions
Available instructions:
```go
Type: PoolL2
// transfer of TokenID=1, from the account A to B (for that token), of 6 units,
// paying a fee of 4
PoolTransfer(1) A-B: 6 (4)
// exit of TokenID=1, from the account A (for that token), of 3 units
PoolExit(1) A: 3
```
## Usage
```go
// create a new til.Context
tc := til.NewContext(eth.RollupConstMaxL1UserTx)
// generate Blockchain blocks data from the common.SetBlockcahin0 instructions set
blocks, err = tc.GenerateBlocks(common.SetBlockchain0)
assert.Nil(t, err)
// generate PoolL2 transactions data from the common.SetPool0 instructions set
poolL2Txs, err = tc.GenerateBlocks(common.SetPool0)
assert.Nil(t, err)
```
Where `blocks` will contain:
```go
// BatchData contains the information of a Batch
type BatchData struct {
L1CoordinatorTxs []common.L1Tx
L2Txs []common.L2Tx
CreatedAccounts []common.Account
}
// BlockData contains the information of a Block
type BlockData struct {
L1UserTxs []common.L1Tx
Batches []BatchData
RegisteredTokens []common.Token
}
```

test/transakcio/lang.go → test/til/lang.go

@ -1,4 +1,4 @@
package transakcio
package til
import ( import (
"bufio" "bufio"

test/transakcio/lang_test.go → test/til/lang_test.go

@ -1,4 +1,4 @@
package transakcio
package til
import ( import (
"fmt" "fmt"

test/transakcio/sets.go → test/til/sets.go

@ -1,4 +1,4 @@
package transakcio
package til
// sets of instructions to be used in tests of other packages // sets of instructions to be used in tests of other packages

test/transakcio/sets_test.go → test/til/sets_test.go

@ -1,4 +1,4 @@
package transakcio
package til
import ( import (
"strings" "strings"
@ -16,7 +16,7 @@ func TestCompileSets(t *testing.T) {
_, err = parser.parse() _, err = parser.parse()
assert.Nil(t, err) assert.Nil(t, err)
tc := NewTestContext(eth.RollupConstMaxL1UserTx)
tc := NewContext(eth.RollupConstMaxL1UserTx)
_, err = tc.GenerateBlocks(SetBlockchain0) _, err = tc.GenerateBlocks(SetBlockchain0)
assert.Nil(t, err) assert.Nil(t, err)
_, err = tc.GenerateBlocks(SetPool0) _, err = tc.GenerateBlocks(SetPool0)

test/transakcio/txs.go → test/til/txs.go

@ -1,4 +1,4 @@
package transakcio
package til
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
@ -15,8 +15,8 @@ import (
"github.com/iden3/go-iden3-crypto/babyjub" "github.com/iden3/go-iden3-crypto/babyjub"
) )
// TestContext contains the data of the test
type TestContext struct {
// Context contains the data of the test
type Context struct {
Instructions []instruction Instructions []instruction
accountsNames []string accountsNames []string
Users map[string]*User Users map[string]*User
@ -35,9 +35,9 @@ type TestContext struct {
openToForge int openToForge int
} }
// NewTestContext returns a new TestContext
func NewTestContext(rollupConstMaxL1UserTx int) *TestContext {
return &TestContext{
// NewContext returns a new Context
func NewContext(rollupConstMaxL1UserTx int) *Context {
return &Context{
Users: make(map[string]*User), Users: make(map[string]*User),
l1CreatedAccounts: make(map[string]*Account), l1CreatedAccounts: make(map[string]*Account),
lastRegisteredTokenID: 0, lastRegisteredTokenID: 0,
@ -82,8 +82,7 @@ type BatchData struct {
L2Txs []common.L2Tx L2Txs []common.L2Tx
// testL2Tx are L2Txs without the Idx&EthAddr&BJJ setted, but with the // testL2Tx are L2Txs without the Idx&EthAddr&BJJ setted, but with the
// string that represents the account // string that represents the account
testL2Txs []L2Tx
CreatedAccounts []common.Account
testL2Txs []L2Tx
} }
// L1Tx is the data structure used internally for transaction test generation, // L1Tx is the data structure used internally for transaction test generation,
@ -109,8 +108,8 @@ type L2Tx struct {
} }
// GenerateBlocks returns an array of BlockData for a given set. It uses the // GenerateBlocks returns an array of BlockData for a given set. It uses the
// accounts (keys & nonces) of the TestContext.
func (tc *TestContext) GenerateBlocks(set string) ([]BlockData, error) {
// accounts (keys & nonces) of the Context.
func (tc *Context) GenerateBlocks(set string) ([]BlockData, error) {
parser := newParser(strings.NewReader(set)) parser := newParser(strings.NewReader(set))
parsedSet, err := parser.parse() parsedSet, err := parser.parse()
if err != nil { if err != nil {
@ -135,7 +134,7 @@ func (tc *TestContext) GenerateBlocks(set string) ([]BlockData, error) {
FromBJJ: tc.Users[inst.from].BJJ.Public(), FromBJJ: tc.Users[inst.from].BJJ.Public(),
TokenID: inst.tokenID, TokenID: inst.tokenID,
LoadAmount: big.NewInt(int64(inst.loadAmount)), LoadAmount: big.NewInt(int64(inst.loadAmount)),
Type: common.TxTypeCreateAccountDeposit, // as txTypeCreateAccountDepositCoordinator is not valid oustide Transakcio package
Type: common.TxTypeCreateAccountDeposit, // as txTypeCreateAccountDepositCoordinator is not valid oustide Til package
} }
testTx := L1Tx{ testTx := L1Tx{
lineNum: inst.lineNum, lineNum: inst.lineNum,
@ -267,7 +266,7 @@ func (tc *TestContext) GenerateBlocks(set string) ([]BlockData, error) {
return nil, err return nil, err
} }
// once Idxs are calculated, update transactions to use the new Idxs
// once Idxs are calculated, update transactions to use the real Idxs
for i := 0; i < len(tc.queues[tc.toForgeNum]); i++ { for i := 0; i < len(tc.queues[tc.toForgeNum]); i++ {
testTx := &tc.queues[tc.toForgeNum][i] testTx := &tc.queues[tc.toForgeNum][i]
if testTx.L1Tx.Type != common.TxTypeCreateAccountDeposit && testTx.L1Tx.Type != common.TxTypeCreateAccountDepositTransfer { if testTx.L1Tx.Type != common.TxTypeCreateAccountDeposit && testTx.L1Tx.Type != common.TxTypeCreateAccountDepositTransfer {
@ -287,6 +286,7 @@ func (tc *TestContext) GenerateBlocks(set string) ([]BlockData, error) {
testTx.L1Tx.BatchNum = &bn testTx.L1Tx.BatchNum = &bn
nTx, err := common.NewL1Tx(&testTx.L1Tx) nTx, err := common.NewL1Tx(&testTx.L1Tx)
if err != nil { if err != nil {
fmt.Println(testTx)
return nil, fmt.Errorf("Line %d: %s", testTx.lineNum, err.Error()) return nil, fmt.Errorf("Line %d: %s", testTx.lineNum, err.Error())
} }
testTx.L1Tx = *nTx testTx.L1Tx = *nTx
@ -327,13 +327,13 @@ func (tc *TestContext) GenerateBlocks(set string) ([]BlockData, error) {
// calculateIdxsForL1Txs calculates new Idx for new created accounts. If // calculateIdxsForL1Txs calculates new Idx for new created accounts. If
// 'isCoordinatorTxs==true', adds the tx to tc.currBatch.L1CoordinatorTxs. // 'isCoordinatorTxs==true', adds the tx to tc.currBatch.L1CoordinatorTxs.
func (tc *TestContext) calculateIdxForL1Txs(isCoordinatorTxs bool, txs []L1Tx) error {
func (tc *Context) calculateIdxForL1Txs(isCoordinatorTxs bool, txs []L1Tx) error {
// for each batch.L1CoordinatorTxs of the queues[ToForgeNum], calculate the Idx // for each batch.L1CoordinatorTxs of the queues[ToForgeNum], calculate the Idx
for i := 0; i < len(txs); i++ { for i := 0; i < len(txs); i++ {
tx := txs[i] tx := txs[i]
if tx.L1Tx.Type == common.TxTypeCreateAccountDeposit || tx.L1Tx.Type == common.TxTypeCreateAccountDepositTransfer { 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 if tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID] != nil { // if account already exists, return error
return fmt.Errorf("Can not create same account twice (same User & same TokenID) (this is a design property of Transakcio)")
return fmt.Errorf("Can not create same account twice (same User & same TokenID) (this is a design property of Til)")
} }
tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID] = &Account{ tc.Users[tx.fromIdxName].Accounts[tx.L1Tx.TokenID] = &Account{
Idx: common.Idx(tc.idx), Idx: common.Idx(tc.idx),
@ -350,7 +350,7 @@ func (tc *TestContext) calculateIdxForL1Txs(isCoordinatorTxs bool, txs []L1Tx) e
} }
// setIdxs sets the Idxs to the transactions of the tc.currBatch // setIdxs sets the Idxs to the transactions of the tc.currBatch
func (tc *TestContext) setIdxs() error {
func (tc *Context) setIdxs() error {
// once Idxs are calculated, update transactions to use the new Idxs // once Idxs are calculated, update transactions to use the new Idxs
for i := 0; i < len(tc.currBatch.testL2Txs); i++ { for i := 0; i < len(tc.currBatch.testL2Txs); i++ {
testTx := &tc.currBatch.testL2Txs[i] testTx := &tc.currBatch.testL2Txs[i]
@ -373,7 +373,7 @@ func (tc *TestContext) setIdxs() error {
} }
nTx, err := common.NewL2Tx(&testTx.L2Tx) nTx, err := common.NewL2Tx(&testTx.L2Tx)
if err != nil { if err != nil {
return err
return fmt.Errorf("Line %d: %s", testTx.lineNum, err.Error())
} }
testTx.L2Tx = *nTx testTx.L2Tx = *nTx
@ -388,7 +388,7 @@ func (tc *TestContext) setIdxs() error {
} }
// addToL1Queue adds the L1Tx into the queue that is open and has space // addToL1Queue adds the L1Tx into the queue that is open and has space
func (tc *TestContext) addToL1Queue(tx L1Tx) {
func (tc *Context) addToL1Queue(tx L1Tx) {
if len(tc.queues[tc.openToForge]) >= tc.rollupConstMaxL1UserTx { if len(tc.queues[tc.openToForge]) >= tc.rollupConstMaxL1UserTx {
// if current OpenToForge queue reached its Max, move into a // if current OpenToForge queue reached its Max, move into a
// new queue // new queue
@ -399,13 +399,13 @@ func (tc *TestContext) addToL1Queue(tx L1Tx) {
tc.queues[tc.openToForge] = append(tc.queues[tc.openToForge], tx) tc.queues[tc.openToForge] = append(tc.queues[tc.openToForge], tx)
} }
func (tc *TestContext) checkIfAccountExists(tf string, inst instruction) error {
func (tc *Context) checkIfAccountExists(tf string, inst instruction) error {
if tc.Users[tf].Accounts[inst.tokenID] == nil { if tc.Users[tf].Accounts[inst.tokenID] == nil {
return fmt.Errorf("%s at User: %s, for TokenID: %d, while account not created yet", inst.typ, tf, inst.tokenID) return fmt.Errorf("%s at User: %s, for TokenID: %d, while account not created yet", inst.typ, tf, inst.tokenID)
} }
return nil return nil
} }
func (tc *TestContext) checkIfTokenIsRegistered(inst instruction) error {
func (tc *Context) checkIfTokenIsRegistered(inst instruction) error {
if inst.tokenID > tc.lastRegisteredTokenID { if inst.tokenID > tc.lastRegisteredTokenID {
return fmt.Errorf("Can not process %s: TokenID %d not registered, last registered TokenID: %d", inst.typ, inst.tokenID, tc.lastRegisteredTokenID) return fmt.Errorf("Can not process %s: TokenID %d not registered, last registered TokenID: %d", inst.typ, inst.tokenID, tc.lastRegisteredTokenID)
} }
@ -413,8 +413,8 @@ func (tc *TestContext) checkIfTokenIsRegistered(inst instruction) error {
} }
// GeneratePoolL2Txs returns an array of common.PoolL2Tx from a given set. It // GeneratePoolL2Txs returns an array of common.PoolL2Tx from a given set. It
// uses the accounts (keys & nonces) of the TestContext.
func (tc *TestContext) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) {
// uses the accounts (keys & nonces) of the Context.
func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) {
parser := newParser(strings.NewReader(set)) parser := newParser(strings.NewReader(set))
parsedSet, err := parser.parse() parsedSet, err := parser.parse()
if err != nil { if err != nil {
@ -492,7 +492,7 @@ func (tc *TestContext) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error)
// generateKeys generates BabyJubJub & Address keys for the given list of // generateKeys generates BabyJubJub & Address keys for the given list of
// account names in a deterministic way. This means, that for the same given // account names in a deterministic way. This means, that for the same given
// 'accNames' in a certain order, the keys will be always the same. // 'accNames' in a certain order, the keys will be always the same.
func (tc *TestContext) generateKeys(accNames []string) {
func (tc *Context) generateKeys(accNames []string) {
for i := 1; i < len(accNames)+1; i++ { for i := 1; i < len(accNames)+1; i++ {
if _, ok := tc.Users[accNames[i-1]]; ok { if _, ok := tc.Users[accNames[i-1]]; ok {
// account already created // account already created

test/transakcio/txs_test.go → test/til/txs_test.go

@ -1,4 +1,4 @@
package transakcio
package til
import ( import (
"math/big" "math/big"
@ -66,7 +66,7 @@ func TestGenerateBlocks(t *testing.T) {
// batch and last block // batch and last block
Transfer(1) User1-User0: 1 (1) Transfer(1) User1-User0: 1 (1)
` `
tc := NewTestContext(eth.RollupConstMaxL1UserTx)
tc := NewContext(eth.RollupConstMaxL1UserTx)
blocks, err := tc.GenerateBlocks(set) blocks, err := tc.GenerateBlocks(set)
require.Nil(t, err) require.Nil(t, err)
assert.Equal(t, 2, len(blocks)) assert.Equal(t, 2, len(blocks))
@ -118,7 +118,7 @@ func TestGenerateBlocks(t *testing.T) {
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(5), common.Nonce(5))
} }
func (tc *TestContext) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, loadAmount, amount *big.Int) {
func (tc *Context) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.TxType, tokenID common.TokenID, from, to string, loadAmount, amount *big.Int) {
assert.Equal(t, typ, tx.Type) assert.Equal(t, typ, tx.Type)
if tx.FromIdx != common.Idx(0) { if tx.FromIdx != common.Idx(0) {
assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx) assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
@ -135,7 +135,7 @@ func (tc *TestContext) checkL1TxParams(t *testing.T, tx common.L1Tx, typ common.
assert.Equal(t, amount, tx.Amount) assert.Equal(t, amount, tx.Amount)
} }
} }
func (tc *TestContext) 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, nonce common.Nonce) {
assert.Equal(t, typ, tx.Type) assert.Equal(t, typ, tx.Type)
assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx) assert.Equal(t, tc.Users[from].Accounts[tokenID].Idx, tx.FromIdx)
if tx.Type != common.TxTypeExit { if tx.Type != common.TxTypeExit {
@ -168,7 +168,7 @@ func TestGeneratePoolL2Txs(t *testing.T) {
> batchL1 > batchL1
> batchL1 > batchL1
` `
tc := NewTestContext(eth.RollupConstMaxL1UserTx)
tc := NewContext(eth.RollupConstMaxL1UserTx)
_, err := tc.GenerateBlocks(set) _, err := tc.GenerateBlocks(set)
require.Nil(t, err) require.Nil(t, err)
set = ` set = `
@ -197,7 +197,7 @@ func TestGeneratePoolL2Txs(t *testing.T) {
assert.Equal(t, common.Nonce(2), poolL2Txs[3].Nonce) assert.Equal(t, common.Nonce(2), poolL2Txs[3].Nonce)
assert.Equal(t, common.Nonce(3), poolL2Txs[8].Nonce) assert.Equal(t, common.Nonce(3), poolL2Txs[8].Nonce)
// load another set in the same TestContext
// load another set in the same Context
set = ` set = `
Type: PoolL2 Type: PoolL2
PoolTransfer(1) A-B: 6 (1) PoolTransfer(1) A-B: 6 (1)
@ -217,7 +217,7 @@ func TestGenerateErrors(t *testing.T) {
CreateAccountDeposit(1) A: 5 CreateAccountDeposit(1) A: 5
> batchL1 > batchL1
` `
tc := NewTestContext(eth.RollupConstMaxL1UserTx)
tc := NewContext(eth.RollupConstMaxL1UserTx)
_, err := tc.GenerateBlocks(set) _, 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())
@ -226,7 +226,7 @@ func TestGenerateErrors(t *testing.T) {
Type: Blockchain Type: Blockchain
RegisterToken(0) RegisterToken(0)
` `
tc = NewTestContext(eth.RollupConstMaxL1UserTx)
tc = NewContext(eth.RollupConstMaxL1UserTx)
_, err = tc.GenerateBlocks(set) _, err = tc.GenerateBlocks(set)
require.Equal(t, "Line 2: RegisterToken can not register TokenID 0", err.Error()) require.Equal(t, "Line 2: RegisterToken can not register TokenID 0", err.Error())
@ -234,7 +234,7 @@ func TestGenerateErrors(t *testing.T) {
Type: Blockchain Type: Blockchain
RegisterToken(2) RegisterToken(2)
` `
tc = NewTestContext(eth.RollupConstMaxL1UserTx)
tc = NewContext(eth.RollupConstMaxL1UserTx)
_, err = tc.GenerateBlocks(set) _, 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: RegisterToken TokenID should be sequential, expected TokenID: 1, defined TokenID: 2", err.Error())
@ -245,7 +245,7 @@ func TestGenerateErrors(t *testing.T) {
RegisterToken(3) RegisterToken(3)
RegisterToken(5) RegisterToken(5)
` `
tc = NewTestContext(eth.RollupConstMaxL1UserTx)
tc = NewContext(eth.RollupConstMaxL1UserTx)
_, err = tc.GenerateBlocks(set) _, 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: RegisterToken TokenID should be sequential, expected TokenID: 4, defined TokenID: 5", err.Error())
@ -259,7 +259,7 @@ func TestGenerateErrors(t *testing.T) {
Transfer(1) A-B: 6 (1) Transfer(1) A-B: 6 (1)
> batch > batch
` `
tc = NewTestContext(eth.RollupConstMaxL1UserTx)
tc = NewContext(eth.RollupConstMaxL1UserTx)
_, err = tc.GenerateBlocks(set) _, 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 = ` set = `
@ -273,7 +273,7 @@ func TestGenerateErrors(t *testing.T) {
Transfer(1) A-B: 6 (1) Transfer(1) A-B: 6 (1)
> batch > batch
` `
tc = NewTestContext(eth.RollupConstMaxL1UserTx)
tc = NewContext(eth.RollupConstMaxL1UserTx)
_, err = tc.GenerateBlocks(set) _, err = tc.GenerateBlocks(set)
require.Nil(t, err) require.Nil(t, err)
@ -286,12 +286,12 @@ func TestGenerateErrors(t *testing.T) {
CreateAccountDepositCoordinator(1) B CreateAccountDepositCoordinator(1) B
> batchL1 > batchL1
Transfer(1) A-B: 6 (1) 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, Transakcio 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) Transfer(1) B-A: 6 (1)
Exit(1) A: 3 Exit(1) A: 3
> batch > batch
` `
tc = NewTestContext(eth.RollupConstMaxL1UserTx)
tc = NewContext(eth.RollupConstMaxL1UserTx)
_, err = tc.GenerateBlocks(set) _, err = tc.GenerateBlocks(set)
require.Nil(t, err) require.Nil(t, err)
assert.Equal(t, common.Nonce(3), tc.Users["A"].Accounts[common.TokenID(1)].Nonce) assert.Equal(t, common.Nonce(3), tc.Users["A"].Accounts[common.TokenID(1)].Nonce)

+ 0
- 9
test/transakcio/utils.go

@ -1,9 +0,0 @@
package transakcio
// TODO
// func extendTokenIDs(o, n []common.TokenID) []common.TokenID {
// return o
// }
// func extendAccounts(o, n map[string]*Account) map[string]*Account {
// return o
// }

+ 2
- 2
txselector/txselector_test.go

@ -39,7 +39,7 @@ func addTokens(t *testing.T, tokens []common.Token, db *sqlx.DB) {
} }
func TestGetL2TxSelection(t *testing.T) { func TestGetL2TxSelection(t *testing.T) {
txsel := initTest(t, transakcio.SetPool0, 5, 5, 10)
txsel := initTest(t, til.SetPool0, 5, 5, 10)
test.CleanL2DB(txsel.l2db.DB()) test.CleanL2DB(txsel.l2db.DB())
// generate test transactions // generate test transactions
@ -57,7 +57,7 @@ func TestGetL2TxSelection(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
// TODO once L2DB is updated to return error in case that AddTxTest // TODO once L2DB is updated to return error in case that AddTxTest
// fails, and the Transakcio is updated, update this test, checking that the
// fails, and the Til is updated, update this test, checking that the
// selected PoolL2Tx are correctly sorted by Nonce // selected PoolL2Tx are correctly sorted by Nonce

Loading…
Cancel
Save