Skip to content

Instantly share code, notes, and snippets.

@Jesserc
Last active August 16, 2024 12:11
Show Gist options
  • Save Jesserc/016bbd6bca0fe6ad321cb02f5b963f9a to your computer and use it in GitHub Desktop.
Save Jesserc/016bbd6bca0fe6ad321cb02f5b963f9a to your computer and use it in GitHub Desktop.
func ToWithdrawalTx(t *testing.T, sender string, target string, amount math.Int) []byte {
withdrawalMsg := &rollupv1.InitiateWithdrawalRequest{
Sender: sender,
Target: target,
Value: amount,
Data: []byte{},
}
// Wrap the message in an Any
msgAny, err := codectypes.NewAnyWithValue(withdrawalMsg)
require.NoError(t, err)
// Create the transaction
tx := &sdktx.Tx{
Body: &sdktx.TxBody{
Messages: []*codectypes.Any{msgAny},
},
AuthInfo: &sdktx.AuthInfo{
Fee: &sdktx.Fee{},
},
}
txBytes, err := tx.Marshal()
require.NoError(t, err)
return txBytes
}
func TestParseWithdrawalMessages(t *testing.T) {
pool := mempool.New(testutils.NewMemDB(t))
// mempoolTxs := testapp.ToTxs(t, map[string]string{
// "k3": "v3",
// "k4": "v4",
// })
// for _, tx := range mempoolTxs {
// require.NoError(t, pool.Enqueue(tx))
// }
blockStore := testutils.NewLocalMemDB(t)
txStore := txstore.NewTxStore(testutils.NewCometMemDB(t))
ethstatedb := testutils.NewEthStateDB(t)
// Chain ID, app and genesis
var chainID monomer.ChainID
app := testapp.NewTest(t, chainID.String())
g := &genesis.Genesis{
ChainID: chainID,
AppState: testapp.MakeGenesisAppState(t, app),
}
// Event bus
eventBus := bfttypes.NewEventBus()
require.NoError(t, eventBus.Start())
t.Cleanup(func() {
require.NoError(t, eventBus.Stop())
})
require.NoError(t, g.Commit(context.Background(), app, blockStore, ethstatedb))
b := builder.New(
pool,
app,
blockStore,
txStore,
eventBus,
g.ChainID,
ethstatedb,
)
msg := testapp.ToWithdrawalTx(t, "abcdef12345", common.HexToAddress("0x12345abcdef").String(), math.NewInt(100))
payload := &builder.Payload{
InjectedTransactions: bfttypes.Txs{msg},
GasLimit: 0,
Timestamp: g.Time + 1,
NoTxPool: false,
}
_, err := b.Build(context.Background(), payload)
require.NoError(t, err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment