Skip to content

Commit e9c4586

Browse files
committed
update
1 parent 483d5e7 commit e9c4586

File tree

8 files changed

+97
-60
lines changed

8 files changed

+97
-60
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ require (
4141
github.com/gorilla/websocket v1.5.3 // indirect
4242
github.com/goware/breaker v0.2.0 // indirect
4343
github.com/goware/cachestore-mem v0.2.2 // indirect
44-
github.com/goware/calc v0.2.0 // indirect
4544
github.com/goware/channel v0.5.0 // indirect
4645
github.com/goware/singleflight v0.3.0 // indirect
4746
github.com/goware/superr v0.0.2 // indirect
@@ -55,7 +54,6 @@ require (
5554
github.com/supranational/blst v0.3.16 // indirect
5655
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
5756
github.com/zeebo/xxh3 v1.0.2 // indirect
58-
golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b // indirect
5957
golang.org/x/net v0.47.0 // indirect
6058
golang.org/x/sync v0.18.0 // indirect
6159
golang.org/x/sys v0.38.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receipts/eth_getlogs_fetch.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ const MaxFilterBlockRange = 7500
1818
// events for the given digest and returns all decoded Sequence receipts along with
1919
// the native receipt.
2020
//
21-
// The `opHash` is also known as the "MetaTxnID"
21+
// The `opHash` is also known as the "MetaTxnID" but please make sure
22+
// it has the "0x" prefix when passing as a common.Hash, even though
23+
// sometimes we represent a MetaTxnID without the 0x prefix as a string.
2224
//
2325
// NOTE: toBlock can also be nil, in which case the latest block is used.
2426
//
@@ -65,15 +67,10 @@ func FetchMetaTransactionReceiptByETHGetLogs(ctx context.Context, opHash common.
6567
return Receipts{}, nil, fmt.Errorf("unable to filter logs: %w", err)
6668
}
6769
if len(logs) == 0 {
68-
// Fallback for legacy events where the digest is not indexed.
69-
query.Topics = [][]common.Hash{{sequence.V3CallSucceeded, sequence.V3CallFailed, sequence.V3CallAborted, sequence.V3CallSkipped}}
70-
logs, err = provider.FilterLogs(ctx, query)
71-
if err != nil {
72-
return Receipts{}, nil, fmt.Errorf("unable to filter logs without digest topic: %w", err)
73-
}
70+
return Receipts{}, nil, ethereum.NotFound
7471
}
7572

76-
log, err := findDigestLog(logs, opHash)
73+
log, err := findV3CallsDigestLog(logs, opHash)
7774
if err != nil {
7875
return Receipts{}, nil, err
7976
}
@@ -92,30 +89,27 @@ func FetchMetaTransactionReceiptByETHGetLogs(ctx context.Context, opHash common.
9289
if receipts == nil {
9390
return Receipts{}, receipt, fmt.Errorf("decoded receipts do not include digest %v", opHash)
9491
}
95-
9692
return *receipts, receipt, nil
9793
}
9894

99-
func findDigestLog(logs []types.Log, digest common.Hash) (*types.Log, error) {
95+
func findV3CallsDigestLog(logs []types.Log, digest common.Hash) (*types.Log, error) {
10096
var selected *types.Log
101-
10297
for i := range logs {
10398
log := &logs[i]
104-
if !matchesDigest(log, digest) {
99+
if !matchesV3CallsDigest(log, digest) {
105100
continue
106101
}
107102
if selected == nil || isNewerLog(log, selected) {
108103
selected = log
109104
}
110105
}
111-
112106
if selected == nil {
113107
return nil, fmt.Errorf("no Call* events found for digest %v", digest)
114108
}
115109
return selected, nil
116110
}
117111

118-
func matchesDigest(log *types.Log, digest common.Hash) bool {
112+
func matchesV3CallsDigest(log *types.Log, digest common.Hash) bool {
119113
if hash, _, err := sequence.V3DecodeCallSucceededEvent(log); err == nil && hash == digest {
120114
return true
121115
}

receipts_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestReceiptDecoding(t *testing.T) {
3030
assert.NoError(t, err)
3131

3232
// Sign and send the transaction
33-
err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
33+
_, err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
3434
assert.NoError(t, err)
3535

3636
var send [][]byte

relayer_test.go

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,31 @@ import (
44
"context"
55
"math/big"
66
"testing"
7+
"time"
78

89
"github.com/0xsequence/ethkit/ethcoder"
10+
"github.com/0xsequence/ethkit/go-ethereum/common"
911
"github.com/0xsequence/ethkit/go-ethereum/core/types"
1012
"github.com/0xsequence/go-sequence"
1113
"github.com/0xsequence/go-sequence/receipts"
1214
"github.com/0xsequence/go-sequence/testutil"
1315
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/require"
1417
)
1518

1619
func TestGetReceiptOfTransaction(t *testing.T) {
1720
// Ensure dummy sequence wallet from seed 1 is deployed
18-
wallet, err := testChain.V1DummySequenceWallet(1)
19-
assert.NoError(t, err)
20-
assert.NotNil(t, wallet)
21+
wallet, err := testChain.V3DummySequenceWallet(1)
22+
require.NoError(t, err)
23+
require.NotNil(t, wallet)
2124

2225
// Create normal txn of: callmockContract.testCall(55, 0x112255)
2326
callmockContract := testChain.UniDeploy(t, "WALLET_CALL_RECV_MOCK", 0)
2427
calldata, err := callmockContract.Encode("testCall", big.NewInt(55), ethcoder.MustHexDecode("0x112255"))
25-
assert.NoError(t, err)
28+
require.NoError(t, err)
2629

2730
nonce, err := wallet.GetNonce()
28-
assert.NoError(t, err)
31+
require.NoError(t, err)
2932

3033
stx := &sequence.Transaction{
3134
To: callmockContract.Address,
@@ -37,20 +40,64 @@ func TestGetReceiptOfTransaction(t *testing.T) {
3740
Nonce: nonce,
3841
}
3942

40-
err = testutil.SignAndSendRawTransaction(t, wallet, stx)
41-
assert.NoError(t, err)
43+
origReceipt, err := testutil.SignAndSendRawTransaction(t, wallet, stx)
44+
require.NoError(t, err)
45+
require.NotNil(t, origReceipt)
46+
t.Logf("original receipt txn hash: %v", origReceipt.TxHash.Hex())
4247

4348
// Get transactions digest
44-
metaTxnID, _, err := sequence.ComputeMetaTxnID(testChain.ChainID(), wallet.Address(), stx.Bundle(), nonce, 0)
45-
assert.NoError(t, err)
46-
assert.NotEmpty(t, metaTxnID)
49+
// Build V3 CallsPayload to compute the exact V3 metaTxnID
50+
// payload := v3.NewCallsPayload(
51+
// wallet.Address(),
52+
// testChain.ChainID(),
53+
// []v3.Call{{
54+
// To: callmockContract.Address,
55+
// Value: big.NewInt(0),
56+
// Data: calldata,
57+
// GasLimit: big.NewInt(190000),
58+
// DelegateCall: false,
59+
// OnlyFallback: false,
60+
// BehaviorOnError: v3.BehaviorOnErrorIgnore,
61+
// }},
62+
// big.NewInt(0), // space
63+
// nonce, // v3 nonce
64+
// )
65+
payload, err := stx.Bundle().Payload(wallet.Address(), testChain.ChainID(), big.NewInt(0), nonce)
66+
require.NoError(t, err)
67+
68+
metaTxnID, _, err := sequence.ComputeMetaTxnIDFromCallsPayload(&payload)
69+
require.NoError(t, err)
70+
require.NotEmpty(t, metaTxnID)
71+
t.Logf("metaTxnID: 0x%s", string(metaTxnID))
72+
73+
// NOTE: we can delay here by uncommenting, which will make it so we don't find the
74+
// receipt in the cache, and we depend on the QueryOnChain function to find it.
75+
time.Sleep(3 * time.Second)
4776

4877
// Find receipt
4978
// status, receipt, err := sequence.WaitForMetaTxn(context.Background(), testChain.Provider, metaTxnId)
5079
result, receipt, _, err := receipts.FetchMetaTransactionReceipt(context.Background(), testChain.ReceiptsListener, metaTxnID)
51-
assert.NoError(t, err)
52-
assert.NotNil(t, receipt)
53-
assert.Equal(t, sequence.MetaTxnExecuted, result.Status)
80+
require.NoError(t, err)
81+
require.NotNil(t, receipt)
82+
require.Equal(t, sequence.MetaTxnExecuted, result.Status)
83+
t.Logf("listener found receipt of txn hash: %v", receipt.TransactionHash().Hex())
84+
85+
// Find receipt again via eth_getLogs method directly
86+
latestBlock := testChain.ReceiptsListener.LatestBlockNum()
87+
fromBlock := new(big.Int).Sub(latestBlock, big.NewInt(5000))
88+
if fromBlock.Cmp(big.NewInt(0)) < 0 {
89+
fromBlock = big.NewInt(0)
90+
}
91+
var toBlock *big.Int = nil
92+
93+
metaTxnHash := common.HexToHash(string(metaTxnID))
94+
_, receipt2, err := receipts.FetchMetaTransactionReceiptByETHGetLogs(context.Background(), metaTxnHash, testChain.ReceiptsListener.RPCProvider(), fromBlock, toBlock)
95+
require.NoError(t, err)
96+
require.NotNil(t, receipt2)
97+
require.Equal(t, types.ReceiptStatusSuccessful, receipt2.Status)
98+
require.Equal(t, receipt.Status(), receipt2.Status)
99+
require.Equal(t, receipt.TransactionHash(), receipt2.TxHash)
100+
t.Logf("fetch via eth_getLogs found receipt of txn hash: %v", receipt2.TxHash.Hex())
54101
}
55102

56103
func TestGetReceiptOfErrorTransaction(t *testing.T) {
@@ -64,7 +111,7 @@ func TestGetReceiptOfErrorTransaction(t *testing.T) {
64111
calldata, err := callmockContract.Encode("setRevertFlag", true)
65112
assert.NoError(t, err)
66113

67-
err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
114+
_, err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
68115
assert.NoError(t, err)
69116

70117
// Call callmock, this should revert and fail the transaction
@@ -84,7 +131,7 @@ func TestGetReceiptOfErrorTransaction(t *testing.T) {
84131
Nonce: nonce,
85132
}
86133

87-
err = testutil.SignAndSendRawTransaction(t, wallet, stx)
134+
_, err = testutil.SignAndSendRawTransaction(t, wallet, stx)
88135
assert.NoError(t, err)
89136

90137
// Get transactions digest
@@ -117,14 +164,14 @@ func TestGetReceiptOfFailedTransactionBetweenTransactions(t *testing.T) {
117164
for i := 1; i <= 3; i++ {
118165
calldata, err := callmockContract.Encode("testCall", big.NewInt(int64(i)), ethcoder.MustHexDecode("0x112255"))
119166
assert.NoError(t, err)
120-
err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
167+
_, err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
121168
assert.NoError(t, err)
122169
}
123170

124171
calldata, err := callmockContract.Encode("setRevertFlag", true)
125172
assert.NoError(t, err)
126173

127-
err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
174+
_, err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
128175
assert.NoError(t, err)
129176

130177
for i := 1; i <= 3; i++ {
@@ -136,7 +183,7 @@ func TestGetReceiptOfFailedTransactionBetweenTransactions(t *testing.T) {
136183
GasLimit: big.NewInt(190000),
137184
RevertOnError: false,
138185
}
139-
err = testutil.SignAndSendRawTransaction(t, wallet, stx)
186+
_, err = testutil.SignAndSendRawTransaction(t, wallet, stx)
140187
assert.NoError(t, err)
141188
}
142189

@@ -156,7 +203,7 @@ func TestGetReceiptOfFailedTransactionBetweenTransactions(t *testing.T) {
156203
Nonce: nonce,
157204
}
158205

159-
err = testutil.SignAndSendRawTransaction(t, wallet, stx)
206+
_, err = testutil.SignAndSendRawTransaction(t, wallet, stx)
160207
assert.NoError(t, err)
161208

162209
for i := 1; i <= 3; i++ {
@@ -168,7 +215,7 @@ func TestGetReceiptOfFailedTransactionBetweenTransactions(t *testing.T) {
168215
GasLimit: big.NewInt(190000),
169216
RevertOnError: false,
170217
}
171-
err = testutil.SignAndSendRawTransaction(t, wallet, stx)
218+
_, err = testutil.SignAndSendRawTransaction(t, wallet, stx)
172219
assert.NoError(t, err)
173220
}
174221

@@ -202,7 +249,7 @@ func TestGetReceiptOfTransactionBetweenTransactions(t *testing.T) {
202249
for i := 1; i <= 3; i++ {
203250
calldata, err := callmockContract.Encode("testCall", big.NewInt(int64(i)), ethcoder.MustHexDecode("0x112255"))
204251
assert.NoError(t, err)
205-
err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
252+
_, err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
206253
assert.NoError(t, err)
207254
}
208255

@@ -222,13 +269,13 @@ func TestGetReceiptOfTransactionBetweenTransactions(t *testing.T) {
222269
Nonce: nonce,
223270
}
224271

225-
err = testutil.SignAndSendRawTransaction(t, wallet, stx)
272+
_, err = testutil.SignAndSendRawTransaction(t, wallet, stx)
226273
assert.NoError(t, err)
227274

228275
for i := 1; i <= 3; i++ {
229276
calldata, err = callmockContract.Encode("testCall", big.NewInt(int64(i)), ethcoder.MustHexDecode("0x112255"))
230277
assert.NoError(t, err)
231-
err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
278+
_, err = testutil.SignAndSend(t, wallet, callmockContract.Address, calldata)
232279
assert.NoError(t, err)
233280
}
234281

testutil/helpers.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/0xsequence/go-sequence/contracts"
2121
"github.com/0xsequence/go-sequence/core"
2222
"github.com/stretchr/testify/assert"
23+
"github.com/stretchr/testify/require"
2324
)
2425

2526
var sequenceContext = sequence.WalletContext{
@@ -42,8 +43,8 @@ var sequenceContextV2 = sequence.WalletContext{
4243

4344
var sequenceContextV3 = sequence.WalletContext{
4445
FactoryAddress: common.HexToAddress("0x00000000000018A77519fcCCa060c2537c9D6d3F"),
45-
MainModuleAddress: common.HexToAddress("0x0000000000001f3C39d61698ab21131a12134454"),
46-
MainModuleUpgradableAddress: common.HexToAddress("0xD0ae8eF93b7DA4eabb32Ec4d81b7a501DCa04D4C"),
46+
MainModuleAddress: common.HexToAddress("0x0000000000001f3C39d61698ab21131a12134454"), // stage 1
47+
MainModuleUpgradableAddress: common.HexToAddress("0xD0ae8eF93b7DA4eabb32Ec4d81b7a501DCa04D4C"), // stage 2
4748
GuestModuleAddress: common.HexToAddress("0x0000000000006Ac72ed1d192fa28f0058D3F8806"),
4849
CreationCode: hexutil.Encode(contracts.V3.CreationCode),
4950
}
@@ -114,7 +115,7 @@ func DummyPrivateKey(seed uint64) string {
114115
return fmt.Sprintf("%064x", seed)
115116
}
116117

117-
func SignAndSend[C core.WalletConfig](t *testing.T, wallet *sequence.Wallet[C], to common.Address, data []byte) error {
118+
func SignAndSend[C core.WalletConfig](t *testing.T, wallet *sequence.Wallet[C], to common.Address, data []byte) (*types.Receipt, error) {
118119
stx := &sequence.Transaction{
119120
// DelegateCall: false,
120121
// RevertOnError: false,
@@ -123,28 +124,27 @@ func SignAndSend[C core.WalletConfig](t *testing.T, wallet *sequence.Wallet[C],
123124
To: to,
124125
Data: data,
125126
}
126-
127127
return SignAndSendRawTransaction(t, wallet, stx)
128128
}
129129

130-
func SignAndSendRawTransaction[C core.WalletConfig](t *testing.T, wallet *sequence.Wallet[C], stx *sequence.Transaction) error {
130+
func SignAndSendRawTransaction[C core.WalletConfig](t *testing.T, wallet *sequence.Wallet[C], stx *sequence.Transaction) (*types.Receipt, error) {
131131
// Now, we must sign the meta txn
132132
signedTx, err := wallet.SignTransaction(context.Background(), stx)
133-
assert.NoError(t, err)
133+
require.NoError(t, err)
134134

135135
metaTxnID, _, waitReceipt, err := wallet.SendTransaction(context.Background(), signedTx)
136-
assert.NoError(t, err)
137-
assert.NotEmpty(t, metaTxnID)
136+
require.NoError(t, err)
137+
require.NotEmpty(t, metaTxnID)
138138

139139
receipt, err := waitReceipt(context.Background())
140-
assert.NoError(t, err)
141-
assert.True(t, receipt.Status == types.ReceiptStatusSuccessful)
140+
require.NoError(t, err)
141+
require.True(t, receipt.Status == types.ReceiptStatusSuccessful)
142142

143143
// TODO: decode the receipt, and lets confirm we have the metaTxnID event in there..
144144
// NOTE: if you start test chain with `make start-testchain-verbose`, you will see the metaTxnID above
145145
// correctly logged..
146146

147-
return err
147+
return receipt, err
148148
}
149149

150150
func BatchSignAndSend[C core.WalletConfig](t *testing.T, wallet *sequence.Wallet[C], to common.Address, data [][]byte) error {

0 commit comments

Comments
 (0)