add test cases

This commit is contained in:
maskpp
2023-04-11 16:13:47 +08:00
parent 0ea67d6882
commit ebe78e86ef
2 changed files with 38 additions and 88 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"os"
"scroll-tech/common/utils"
"strconv"
"strings"
"testing"
@@ -236,15 +237,22 @@ func testL2CheckSubmittedMessages(t *testing.T) {
assert.NotNil(t, relayer)
err = relayer.CheckSubmittedMessages()
assert.Nil(t, err)
relayer.WaitSubmittedMessages()
// check tx is confirmed.
maxNonce, txMsgs, err := db.GetL2TxMessages(
map[string]interface{}{"status": types.MsgConfirmed},
fmt.Sprintf("AND nonce > %d", 0),
fmt.Sprintf("ORDER BY nonce ASC LIMIT %d", 10),
var (
maxNonce uint64
txMsgs []*types.ScrollTx
)
utils.TryTimes(5, func() bool {
// check tx is confirmed.
maxNonce, txMsgs, err = db.GetL2TxMessages(
map[string]interface{}{"status": types.MsgConfirmed},
fmt.Sprintf("AND nonce > %d", 0),
fmt.Sprintf("ORDER BY nonce ASC LIMIT %d", 10),
)
return err == nil
})
assert.Nil(t, err)
assert.Equal(t, 1, len(txMsgs))
assert.Equal(t, templateL2Message[0].Nonce, maxNonce)
@@ -301,14 +309,18 @@ func testL2CheckRollupCommittingBatches(t *testing.T) {
assert.NoError(t, relayer.CheckRollupCommittingBatches())
relayer.WaitRollupCommittingBatches()
// check tx is confirmed.
txMsgs, err := db.GetScrollTxs(
map[string]interface{}{
"type": types.RollUpCommitTx,
"confirm": true,
},
"ORDER BY nonce ASC",
)
var txMsgs []*types.ScrollTx
utils.TryTimes(5, func() bool {
// check tx is confirmed.
txMsgs, err = db.GetScrollTxs(
map[string]interface{}{
"type": types.RollUpCommitTx,
"confirm": true,
},
"ORDER BY nonce ASC",
)
return err == nil
})
assert.NoError(t, err)
assert.Equal(t, 1, len(txMsgs))
assert.Equal(t, "", txMsgs[0].ExtraData.String)
@@ -363,14 +375,18 @@ func testL2CheckRollupFinalizingBatches(t *testing.T) {
assert.NoError(t, relayer.CheckRollupFinalizingBatches())
relayer.WaitRollupFinalizingBatches()
// check tx is confirmed.
txMsgs, err := db.GetScrollTxs(
map[string]interface{}{
"type": types.RollupFinalizeTx,
"confirm": true,
},
"ORDER BY nonce ASC",
)
var txMsgs []*types.ScrollTx
utils.TryTimes(5, func() bool {
// check tx is confirmed.
txMsgs, err = db.GetScrollTxs(
map[string]interface{}{
"type": types.RollupFinalizeTx,
"confirm": true,
},
"ORDER BY nonce ASC",
)
return err == nil
})
assert.NoError(t, err)
assert.Equal(t, 1, len(txMsgs))
assert.Equal(t, "", txMsgs[0].ExtraData.String)

View File

@@ -196,69 +196,3 @@ func (t *scrollTxOrm) GetBlockBatchTxMessages(fields map[string]interface{}, arg
}
return index, txMsgs, nil
}
/*
func (t *scrollTxOrm) GetL1GasPriceOracleTxMessage(fields map[string]interface{}, args ...string) (uint64, []*stypes.ScrollTx, error) {
query := "select hash, number from l1_block where 1 = 1"
for key := range fields {
query = query + fmt.Sprintf(" AND %s = :%s", key, key)
}
query = strings.Join(append([]string{query}, args...), " ")
query = fmt.Sprintf("select l1b.number as number, bt.hash as id, tx.tx_hash, tx.sender, tx.nonce, tx.target, tx.value, tx.data from transaction as tx right join (%s) as l1b on tx.id = l1b.hash;", query)
db := t.db
rows, err := db.NamedQuery(db.Rebind(query), fields)
if err != nil {
return 0, nil, err
}
var (
number uint64
txMsgs []*stypes.ScrollTx
)
for rows.Next() {
warp := struct {
Number uint64 `db:"number"`
*stypes.ScrollTx
}{}
if err = rows.StructScan(&warp); err != nil {
return 0, nil, err
}
number = mathutil.MaxUint64(number, warp.Number)
txMsgs = append(txMsgs, warp.ScrollTx)
}
return number, txMsgs, nil
}
func (t *scrollTxOrm) GetL2GasPriceOracleTxMessage(fields map[string]interface{}, args ...string) (uint64, []*stypes.ScrollTx, error) {
query := "select hash, index from block_batch where 1 = 1"
for key := range fields {
query = query + fmt.Sprintf(" AND %s = :%s", key, key)
}
query = strings.Join(append([]string{query}, args...), " ")
query = fmt.Sprintf("select bt.index as index, bt.hash as id, tx.tx_hash, tx.sender, tx.nonce, tx.target, tx.value, tx.data from transaction as tx right join (%s) as bt on tx.id = bt.hash;", query)
db := t.db
rows, err := db.NamedQuery(db.Rebind(query), fields)
if err != nil {
return 0, nil, err
}
var (
index uint64
txMsgs []*stypes.ScrollTx
)
for rows.Next() {
warp := struct {
Index uint64 `db:"index"`
*stypes.ScrollTx
}{}
if err = rows.StructScan(&warp); err != nil {
return 0, nil, err
}
index = mathutil.MaxUint64(index, warp.Index)
txMsgs = append(txMsgs, warp.ScrollTx)
}
return index, txMsgs, nil
}
*/