Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/sync test scenarios #59

Merged
merged 14 commits into from
Nov 13, 2024
Merged
1 change: 1 addition & 0 deletions sequencer/database/migrations/0001.sql
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ CREATE TABLE tx (
amount_success BOOLEAN NOT NULL DEFAULT true,
amount_f NUMERIC NOT NULL,
-- token_id INT NOT NULL REFERENCES token (token_id),
token_id INT,
amount_usd NUMERIC, -- Value of the amount in USD at the moment the tx was inserted in the DB
batch_num BIGINT REFERENCES batch (batch_num) ON DELETE SET NULL, -- Can be NULL in the case of L1 txs that are on the queue but not forged yet.
eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
Expand Down
3 changes: 1 addition & 2 deletions sequencer/test/til/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"math/big"
"sort"
"strconv"
"tokamak-sybil-resistance/common"
"tokamak-sybil-resistance/log"
Expand Down Expand Up @@ -486,6 +485,6 @@ func (p *parser) parse() (*parsedSet, error) {
for u := range users {
ps.users = append(ps.users, u)
}
sort.Strings(ps.users)
// sort.Strings(ps.users)
return ps, nil
}
19 changes: 8 additions & 11 deletions sequencer/test/til/txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ func (tc *Context) generateBlocks() ([]common.BlockData, error) {
tc.accountsByIdx[tc.idx] = tc.Accounts[tx.fromIdxName]
tc.idx++
}
for _, tx := range tc.currBatchTest.l1CoordinatorTxs {
tc.l1CreatedAccounts[tx.fromIdxName] = tc.Accounts[tx.fromIdxName]
tc.accountsByIdx[tc.idx] = tc.Accounts[tx.fromIdxName]
tc.idx++
}
// for _, tx := range tc.currBatchTest.l1CoordinatorTxs {
// tc.l1CreatedAccounts[tx.fromIdxName] = tc.Accounts[tx.fromIdxName]
// tc.accountsByIdx[tc.idx] = tc.Accounts[tx.fromIdxName]
// tc.idx++
// }
tc.currBatch.L1Batch = true
if err := tc.setIdxs(); err != nil {
return nil, common.Wrap(err)
Expand Down Expand Up @@ -512,7 +512,7 @@ func (tc *Context) generatePoolL2Txs() ([]common.PoolL2Tx, error) {
// ToIdx, and use only ToEthAddr & ToBJJ
tx := common.PoolL2Tx{
FromIdx: tc.Accounts[inst.From].Idx,
Amount: big.NewInt(1),
Amount: big.NewInt(0),
Fee: common.FeeSelector(inst.Fee),
Nonce: tc.Accounts[inst.From].Nonce,
State: common.PoolL2TxStatePending,
Expand All @@ -527,9 +527,6 @@ func (tc *Context) generatePoolL2Txs() ([]common.PoolL2Tx, error) {
tx.ToEthAddr = common.EmptyAddr
tx.ToBJJ = common.EmptyBJJComp
}
if inst.LineNum == 3 {
// panic(tx.Type)
}
nTx, err := common.NewPoolL2Tx(&tx)
if err != nil {
return nil, common.Wrap(fmt.Errorf("line %d: %s", inst.LineNum, err.Error()))
Expand Down Expand Up @@ -622,10 +619,10 @@ func NewUser(keyDerivationIndex int, name string) Account {
idx := common.AccountIdx(255 + keyDerivationIndex)

// Balance
balance := big.NewInt(int64(keyDerivationIndex))
balance := big.NewInt(0)

// Nonce
nonce := common.Nonce(keyDerivationIndex)
nonce := common.Nonce(0)

// BatchNum

Expand Down
22 changes: 12 additions & 10 deletions sequencer/test/til/txs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,7 @@ func TestGeneratePoolL2Txs(t *testing.T) {
set := `
Type: Blockchain
CreateAccountDeposit A: 10
CreateAccountDeposit A: 20
CreateAccountDeposit B: 5
CreateAccountDeposit C: 5
CreateAccountDeposit User0: 5
CreateAccountDeposit User1: 0
CreateAccountDeposit User0: 0
CreateAccountDeposit User1: 5
CreateAccountDeposit B: 5
CreateAccountDeposit D: 0
> batchL1
Expand All @@ -178,13 +172,21 @@ func TestGeneratePoolL2Txs(t *testing.T) {
require.NoError(t, err)
set = `
Type: PoolL2
PoolCreateVouch A-B
PoolCreateVouch A-C
PoolDeleteVouch A-C
PoolExit A: 3
`
poolL2Txs, err := tc.GeneratePoolL2Txs(set)
require.NoError(t, err)
assert.Equal(t, 1, len(poolL2Txs))
assert.Equal(t, common.TxTypeExit, poolL2Txs[0].Type)
assert.Equal(t, common.Nonce(1), poolL2Txs[0].Nonce)
assert.Equal(t, 4, len(poolL2Txs))
assert.Equal(t, common.TxTypeCreateVouch, poolL2Txs[0].Type)
assert.Equal(t, common.TxTypeDeleteVouch, poolL2Txs[2].Type)
assert.Equal(t, common.TxTypeExit, poolL2Txs[3].Type)
assert.Equal(t, common.Nonce(0), poolL2Txs[0].Nonce)
assert.Equal(t, common.Nonce(1), poolL2Txs[1].Nonce)
assert.Equal(t, common.Nonce(2), poolL2Txs[2].Nonce)
assert.Equal(t, common.Nonce(3), poolL2Txs[3].Nonce)

// load another set in the same Context
set = `
Expand All @@ -193,7 +195,7 @@ func TestGeneratePoolL2Txs(t *testing.T) {
`
poolL2Txs, err = tc.GeneratePoolL2Txs(set)
require.NoError(t, err)
assert.Equal(t, common.Nonce(2), poolL2Txs[0].Nonce)
assert.Equal(t, common.Nonce(0), poolL2Txs[0].Nonce)
}

func TestGenerateErrors(t *testing.T) {
Expand Down
Loading