Skip to content

Commit

Permalink
fix e2e + unit test types
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR552 committed Nov 19, 2024
1 parent 89bef95 commit dfe09c2
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion bridgectrl/merkletree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func TestBuildMTRootAndStore(t *testing.T) {
require.Equal(t, len(leaves), len(result))
require.Equal(t, leaves[i][:], result[i].Leaf.Bytes())
require.Equal(t, newRoot, result[i].Root)
require.Equal(t, uint(i+1), result[i].RollupId)
require.Equal(t, uint32(i+1), result[i].RollupId)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions claimtxman/claimtxman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ func TestUpdateDepositStatus(t *testing.T) {
require.NoError(t, err)
require.Len(t, deposits, 1)
require.True(t, deposits[0].ReadyForClaim)
require.Equal(t, uint(1), deposits[0].DepositCount)
require.Equal(t, uint(0), deposits[0].NetworkID)
require.Equal(t, uint32(1), deposits[0].DepositCount)
require.Equal(t, uint32(0), deposits[0].NetworkID)

require.NoError(t, pg.UpdateL2DepositsStatus(ctx, l2Root, 1, 1, nil))
deposits, err = pg.GetDeposits(ctx, destAdr, 10, 0, nil)
Expand Down
4 changes: 2 additions & 2 deletions db/pgstorage/migrations/0007_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (m migrationTest0007) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB)
)
getClaimSQL := "SELECT index, orig_net, orig_addr, amount, dest_addr, block_id, network_id, tx_hash, rollup_index, mainnet_flag FROM sync.claim WHERE index = $1 AND network_id = $2"
_ = db.QueryRow(getClaimSQL, 3, 1).Scan(&claim.Index, &claim.OriginalNetwork, &claim.OriginalAddress, &amount, &claim.DestinationAddress, &claim.BlockID, &claim.NetworkID, &claim.TxHash, &claim.RollupIndex, &claim.MainnetFlag)
assert.Equal(t, uint64(0), claim.RollupIndex)
assert.Equal(t, uint32(0), claim.RollupIndex)
assert.Equal(t, false, claim.MainnetFlag)

insertClaim := "INSERT INTO sync.Claim (network_id, index, orig_net, orig_addr, amount, dest_addr, block_id, tx_hash, rollup_index, mainnet_flag) VALUES(1, 4, 0, decode('0000000000000000000000000000000000000000','hex'), '300000000000000000', decode('14567C0DCF79C20FE1A21E36EC975D1775A1905C','hex'), 2, decode('A9505DB7D7EDD08947F12F2B1F7898148FFB43D80BCB977B78161EF14173D575','hex'), 37, true);"
Expand All @@ -71,7 +71,7 @@ func (m migrationTest0007) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB)
getClaimSQL = "SELECT index, orig_net, orig_addr, amount, dest_addr, block_id, network_id, tx_hash, rollup_index, mainnet_flag FROM sync.claim WHERE index = $1 AND network_id = $2"
_ = db.QueryRow(getClaimSQL, 4, 1).Scan(&claim.Index, &claim.OriginalNetwork, &claim.OriginalAddress, &amount, &claim.DestinationAddress, &claim.BlockID, &claim.NetworkID, &claim.TxHash, &claim.RollupIndex, &claim.MainnetFlag)
assert.NoError(t, err)
assert.Equal(t, uint64(37), claim.RollupIndex)
assert.Equal(t, uint32(37), claim.RollupIndex)
assert.Equal(t, true, claim.MainnetFlag)
}

Expand Down
14 changes: 7 additions & 7 deletions db/pgstorage/pgstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (p *PostgresStorage) GetPreviousBlock(ctx context.Context, networkID uint32
}

// GetNumberDeposits gets the number of deposits.
func (p *PostgresStorage) GetNumberDeposits(ctx context.Context, networkID uint, blockNumber uint64, dbTx pgx.Tx) (uint64, error) {
func (p *PostgresStorage) GetNumberDeposits(ctx context.Context, networkID uint32, blockNumber uint64, dbTx pgx.Tx) (uint64, error) {
var nDeposits int64
const getNumDepositsSQL = "SELECT coalesce(MAX(deposit_cnt), -1) FROM sync.deposit as d INNER JOIN sync.block as b ON d.network_id = b.network_id AND d.block_id = b.id WHERE d.network_id = $1 AND b.block_num <= $2"
err := p.getExecQuerier(dbTx).QueryRow(ctx, getNumDepositsSQL, networkID, blockNumber).Scan(&nDeposits)
Expand Down Expand Up @@ -239,7 +239,7 @@ func (p *PostgresStorage) GetClaim(ctx context.Context, depositCount, originNetw
}

// GetDeposit gets a specific deposit from the storage.
func (p *PostgresStorage) GetDeposit(ctx context.Context, depositCounterUser uint, networkID uint, dbTx pgx.Tx) (*etherman.Deposit, error) {
func (p *PostgresStorage) GetDeposit(ctx context.Context, depositCounterUser, networkID uint32, dbTx pgx.Tx) (*etherman.Deposit, error) {
var (
deposit etherman.Deposit
amount string
Expand Down Expand Up @@ -364,7 +364,7 @@ func (p *PostgresStorage) GetDepositCountByRoot(ctx context.Context, root []byte
}

// CheckIfRootExists checks that the root exists on the db.
func (p *PostgresStorage) CheckIfRootExists(ctx context.Context, root []byte, network uint8, dbTx pgx.Tx) (bool, error) {
func (p *PostgresStorage) CheckIfRootExists(ctx context.Context, root []byte, network uint32, dbTx pgx.Tx) (bool, error) {
var count uint
const getDepositCountByRootSQL = "SELECT count(*) FROM mt.root WHERE root = $1 AND network = $2"
err := p.getExecQuerier(dbTx).QueryRow(ctx, getDepositCountByRootSQL, root, network).Scan(&count)
Expand All @@ -378,7 +378,7 @@ func (p *PostgresStorage) CheckIfRootExists(ctx context.Context, root []byte, ne
}

// GetRoot gets root by the deposit count from the merkle tree.
func (p *PostgresStorage) GetRoot(ctx context.Context, depositCnt uint32, network uint32, dbTx pgx.Tx) ([]byte, error) {
func (p *PostgresStorage) GetRoot(ctx context.Context, depositCnt, network uint32, dbTx pgx.Tx) ([]byte, error) {
var root []byte
const getRootByDepositCntSQL = "SELECT root FROM mt.root inner join sync.deposit on mt.root.deposit_id = sync.deposit.id WHERE sync.deposit.deposit_cnt = $1 AND network = $2"
err := p.getExecQuerier(dbTx).QueryRow(ctx, getRootByDepositCntSQL, depositCnt, network).Scan(&root)
Expand Down Expand Up @@ -519,7 +519,7 @@ func (p *PostgresStorage) GetClaimCount(ctx context.Context, destAddr string, db
}

// GetClaims gets the claim list which be smaller than index.
func (p *PostgresStorage) GetClaims(ctx context.Context, destAddr string, limit uint32, offset uint32, dbTx pgx.Tx) ([]*etherman.Claim, error) {
func (p *PostgresStorage) GetClaims(ctx context.Context, destAddr string, limit, offset uint32, dbTx pgx.Tx) ([]*etherman.Claim, error) {
const getClaimsSQL = "SELECT index, orig_net, orig_addr, amount, dest_addr, block_id, network_id, tx_hash, rollup_index, mainnet_flag FROM sync.claim WHERE dest_addr = $1 ORDER BY block_id DESC LIMIT $2 OFFSET $3"
rows, err := p.getExecQuerier(dbTx).Query(ctx, getClaimsSQL, common.FromHex(destAddr), limit, offset)
if err != nil {
Expand All @@ -543,7 +543,7 @@ func (p *PostgresStorage) GetClaims(ctx context.Context, destAddr string, limit
}

// GetDeposits gets the deposit list which be smaller than depositCount.
func (p *PostgresStorage) GetDeposits(ctx context.Context, destAddr string, limit uint, offset uint, dbTx pgx.Tx) ([]*etherman.Deposit, error) {
func (p *PostgresStorage) GetDeposits(ctx context.Context, destAddr string, limit, offset uint32, dbTx pgx.Tx) ([]*etherman.Deposit, error) {
const getDepositsSQL = "SELECT d.id, leaf_type, orig_net, orig_addr, amount, dest_net, dest_addr, deposit_cnt, block_id, b.block_num, d.network_id, tx_hash, metadata, ready_for_claim FROM sync.deposit as d INNER JOIN sync.block as b ON d.network_id = b.network_id AND d.block_id = b.id WHERE dest_addr = $1 ORDER BY d.block_id DESC, d.deposit_cnt DESC LIMIT $2 OFFSET $3"
rows, err := p.getExecQuerier(dbTx).Query(ctx, getDepositsSQL, common.FromHex(destAddr), limit, offset)
if err != nil {
Expand Down Expand Up @@ -676,7 +676,7 @@ func (p *PostgresStorage) GetClaimTxsByStatus(ctx context.Context, statuses []ct
}

// GetPendingDepositsToClaim gets the deposit list which is not claimed in the destination network.
func (p *PostgresStorage) GetPendingDepositsToClaim(ctx context.Context, destAddress common.Address, destNetwork uint64, leafType, limit uint32, offset uint64, dbTx pgx.Tx) ([]*etherman.Deposit, uint64, error) {
func (p *PostgresStorage) GetPendingDepositsToClaim(ctx context.Context, destAddress common.Address, destNetwork, leafType, limit, offset uint32, dbTx pgx.Tx) ([]*etherman.Deposit, uint64, error) {
desAddrSQL := ""
if destAddress != (common.Address{}) {
str := strings.TrimPrefix(destAddress.String(), "0x")
Expand Down
40 changes: 20 additions & 20 deletions db/pgstorage/pgstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,25 @@ func TestGetLeaves(t *testing.T) {
assert.Equal(t, "0xa4bfa0908dc7b06d98da4309f859023d6947561bc19bc00d77f763dea1a0b9f6", leaves[0].Leaf.String())
assert.Equal(t, uint64(5), leaves[0].ID)
assert.Equal(t, uint64(2), leaves[0].BlockID)
assert.Equal(t, uint(1), leaves[0].RollupId)
assert.Equal(t, uint32(1), leaves[0].RollupId)
assert.Equal(t, "0x42d3339fe8eb57770953423f20a029e778a707e8d58aaf110b40d5eb4dd25722", leaves[0].Root.String())

assert.Equal(t, "0x315fee1aa202bf4a6bd0fde560c89be90b6e6e2aaf92dc5e8d118209abc34110", leaves[1].Leaf.String())
assert.Equal(t, uint64(8), leaves[1].ID)
assert.Equal(t, uint64(1), leaves[1].BlockID)
assert.Equal(t, uint(2), leaves[1].RollupId)
assert.Equal(t, uint32(2), leaves[1].RollupId)
assert.Equal(t, "0x42d3339fe8eb57770953423f20a029e778a707e8d58aaf110b40d5eb4dd25722", leaves[1].Root.String())

assert.Equal(t, "0xb598ce65aa15c08dda126a2985ba54f0559eaac562bb43ba430c7344261fbc5e", leaves[2].Leaf.String())
assert.Equal(t, uint64(7), leaves[2].ID)
assert.Equal(t, uint64(2), leaves[2].BlockID)
assert.Equal(t, uint(3), leaves[2].RollupId)
assert.Equal(t, uint32(3), leaves[2].RollupId)
assert.Equal(t, "0x42d3339fe8eb57770953423f20a029e778a707e8d58aaf110b40d5eb4dd25722", leaves[2].Root.String())

assert.Equal(t, "0xe6585bdf74b6a46b9ede8b1b877e1232fb79ee93106c4db8ffd49cf1685bf243", leaves[3].Leaf.String())
assert.Equal(t, uint64(6), leaves[3].ID)
assert.Equal(t, uint64(2), leaves[3].BlockID)
assert.Equal(t, uint(4), leaves[3].RollupId)
assert.Equal(t, uint32(4), leaves[3].RollupId)
assert.Equal(t, "0x42d3339fe8eb57770953423f20a029e778a707e8d58aaf110b40d5eb4dd25722", leaves[3].Root.String())
}

Expand Down Expand Up @@ -193,50 +193,50 @@ func TestGetPendingDepositsToClaim(t *testing.T) {

_, err = store.Exec(ctx, data)
require.NoError(t, err)
deposits, depositCount, err := store.GetPendingDepositsToClaim(ctx, common.Address{}, 1, 0, 2, 0, nil)
deposits, totalCount, err := store.GetPendingDepositsToClaim(ctx, common.Address{}, 1, 0, 2, 0, nil)
require.NoError(t, err)
assert.Equal(t, 2, len(deposits))
assert.Equal(t, uint64(2), depositCount)
assert.Equal(t, uint64(2), totalCount)
assert.Equal(t, uint8(0), deposits[0].LeafType)
assert.Equal(t, uint(0), deposits[0].NetworkID)
assert.Equal(t, uint(0), deposits[0].OriginalNetwork)
assert.Equal(t, uint32(0), deposits[0].NetworkID)
assert.Equal(t, uint32(0), deposits[0].OriginalNetwork)
assert.Equal(t, common.Address{}, deposits[0].OriginalAddress)
assert.Equal(t, big.NewInt(90000000000000000), deposits[0].Amount)
assert.Equal(t, uint(1), deposits[0].DestinationNetwork)
assert.Equal(t, uint32(1), deposits[0].DestinationNetwork)
assert.Equal(t, common.HexToAddress("0xF39FD6E51AAD88F6F4CE6AB8827279CFFFB92266"), deposits[0].DestinationAddress)
assert.Equal(t, uint64(1), deposits[0].BlockID)
assert.Equal(t, uint(1), deposits[0].DepositCount)
assert.Equal(t, uint32(1), deposits[0].DepositCount)
assert.Equal(t, common.HexToHash("0x6282FACE883070640F802CE8A2C42593AA18D3A691C61BA006EC477D6E5FEE1F"), deposits[0].TxHash)
assert.Equal(t, []byte{}, deposits[0].Metadata)
assert.Equal(t, uint64(2), deposits[0].Id)
assert.Equal(t, true, deposits[0].ReadyForClaim)
assert.Equal(t, uint8(0), deposits[1].LeafType)
assert.Equal(t, uint(0), deposits[1].NetworkID)
assert.Equal(t, uint(0), deposits[1].OriginalNetwork)
assert.Equal(t, uint32(0), deposits[1].NetworkID)
assert.Equal(t, uint32(0), deposits[1].OriginalNetwork)
assert.Equal(t, common.Address{}, deposits[1].OriginalAddress)
assert.Equal(t, big.NewInt(90000000000000000), deposits[1].Amount)
assert.Equal(t, uint(1), deposits[1].DestinationNetwork)
assert.Equal(t, uint32(1), deposits[1].DestinationNetwork)
assert.Equal(t, common.HexToAddress("0xF38FD6E51AAD88F6F4CE6AB8827279CFFFB92266"), deposits[1].DestinationAddress)
assert.Equal(t, uint64(1), deposits[1].BlockID)
assert.Equal(t, uint(2), deposits[1].DepositCount)
assert.Equal(t, uint32(2), deposits[1].DepositCount)
assert.Equal(t, common.HexToHash("0x6282FACE883070640F802CE8A2C42593AA18D3A691C61BA006EC477D6E5FEE1F"), deposits[1].TxHash)
assert.Equal(t, []byte{}, deposits[1].Metadata)
assert.Equal(t, uint64(3), deposits[1].Id)
assert.Equal(t, true, deposits[1].ReadyForClaim)

deposits, depositCount, err = store.GetPendingDepositsToClaim(ctx, common.HexToAddress("0xF39FD6E51AAD88F6F4CE6AB8827279CFFFB92266"), 1, 0, 2, 0, nil)
deposits, totalCount, err = store.GetPendingDepositsToClaim(ctx, common.HexToAddress("0xF39FD6E51AAD88F6F4CE6AB8827279CFFFB92266"), 1, 0, 2, 0, nil)
require.NoError(t, err)
assert.Equal(t, 1, len(deposits))
assert.Equal(t, uint64(1), depositCount)
assert.Equal(t, uint64(1), totalCount)
assert.Equal(t, uint8(0), deposits[0].LeafType)
assert.Equal(t, uint(0), deposits[0].NetworkID)
assert.Equal(t, uint(0), deposits[0].OriginalNetwork)
assert.Equal(t, uint32(0), deposits[0].NetworkID)
assert.Equal(t, uint32(0), deposits[0].OriginalNetwork)
assert.Equal(t, common.Address{}, deposits[0].OriginalAddress)
assert.Equal(t, big.NewInt(90000000000000000), deposits[0].Amount)
assert.Equal(t, uint(1), deposits[0].DestinationNetwork)
assert.Equal(t, uint32(1), deposits[0].DestinationNetwork)
assert.Equal(t, common.HexToAddress("0xF39FD6E51AAD88F6F4CE6AB8827279CFFFB92266"), deposits[0].DestinationAddress)
assert.Equal(t, uint64(1), deposits[0].BlockID)
assert.Equal(t, uint(1), deposits[0].DepositCount)
assert.Equal(t, uint32(1), deposits[0].DepositCount)
assert.Equal(t, common.HexToHash("0x6282FACE883070640F802CE8A2C42593AA18D3A691C61BA006EC477D6E5FEE1F"), deposits[0].TxHash)
assert.Equal(t, []byte{}, deposits[0].Metadata)
assert.Equal(t, uint64(2), deposits[0].Id)
Expand Down
4 changes: 2 additions & 2 deletions db/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ func TestMTStorage(t *testing.T) {

count, err := pg.GetLastDepositCount(ctx, 0, tx)
require.NoError(t, err)
require.Equal(t, uint(0), count)
require.Equal(t, uint32(0), count)

dCount, err := pg.GetDepositCountByRoot(ctx, root, 0, tx)
require.NoError(t, err)
require.Equal(t, uint(0), dCount)
require.Equal(t, uint32(0), dCount)

require.NoError(t, tx.Commit(ctx))
}
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/bridge_network_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestCLaimAlreadyClaimedDepositL2toL1(t *testing.T) {
func TestClaimAlreadyClaimedDepositL2toL1(t *testing.T) {
if testing.Short() {
t.Skip()
}
Expand All @@ -33,7 +33,7 @@ func TestCLaimAlreadyClaimedDepositL2toL1(t *testing.T) {
require.NoError(t, err)
fmt.Println("Deposit: ", deposit)

err = manualClaimDeposit(ctx, testData, deposit)
err = manualClaimDeposit(ctx, testData, deposit, true)
if !isAlreadyClaimedError(err) {
require.NoError(t, err)
}
Expand Down Expand Up @@ -93,8 +93,8 @@ func TestEthTransferL2toL1(t *testing.T) {
fmt.Println("ETH Balance ", ethInitialBalances.String())
amount := big.NewInt(12344321)
txAssetHash := assetEthL2ToL1(ctx, testData, t, amount)
deposit, err := waitDepositToBeReadyToClaim(ctx, testData, txAssetHash, maxTimeToClaimReady)
deposit, err := waitDepositToBeReadyToClaim(ctx, testData, txAssetHash, maxTimeToClaimReady, "")
require.NoError(t, err)
err = manualClaimDeposit(ctx, testData, deposit)
err = manualClaimDeposit(ctx, testData, deposit, true)
require.NoError(t, err)
}
4 changes: 2 additions & 2 deletions test/e2e/bridge_network_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ func manualClaimDeposit(ctx context.Context, testData *bridge2e2TestData, deposi
return err
}

func generateGlobalIndex(deposit *pb.Deposit, rollupID uint) *big.Int {
func generateGlobalIndex(deposit *pb.Deposit, rollupID uint32) *big.Int {
mainnetFlag := deposit.NetworkId == 0
rollupIndex := rollupID - 1
localExitRootIndex := uint(deposit.DepositCnt)
localExitRootIndex := deposit.DepositCnt
globalIndex := etherman.GenerateGlobalIndex(mainnetFlag, rollupIndex, localExitRootIndex)
return globalIndex
}
Expand Down
Loading

0 comments on commit dfe09c2

Please sign in to comment.