-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevertreason_test.go
More file actions
49 lines (42 loc) · 1.71 KB
/
revertreason_test.go
File metadata and controls
49 lines (42 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package revertreason_test
import (
"testing"
revertreason "github.com/PositionExchange/go-get-reverted-reason"
"github.com/magiconair/properties/assert"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
func TestGetRevertReasonPosiChain(t *testing.T) {
// Replace with your Ethereum client URL
client, err := ethclient.Dial("https://api.s0.t.posichain.org/")
if err != nil {
panic(err)
}
// Replace with the failed transaction hash
txHash := common.HexToHash("0x3c2bacb88c4f5cb08fc88130d97b6b4ba978c49b11b12057e9f8357dd43e988e")
revertReason, err := revertreason.GetRevertReason(client, txHash)
t.Log(revertReason)
assert.Equal(t, err, nil)
assert.Equal(t, revertReason, "execution reverted: 26")
// This transaction success
revertReason, err = revertreason.GetRevertReason(client, common.HexToHash("0x3673103a600723d7122f6927bd179b181588073ea43b6fa979c464b8f15a6e71"))
assert.Equal(t, err, nil)
assert.Equal(t, revertReason, "")
}
func TestGetRevertReasonPosiChainBSC(t *testing.T) {
// Replace with your Ethereum client URL
client, err := ethclient.Dial("https://bsc-dataseed.binance.org/")
if err != nil {
panic(err)
}
// Replace with the failed transaction hash
txHash := common.HexToHash("0xdba10e26e2061bc3474b0d2ebcd666298da1bbc60b7adb07105dc022af6cfd2a")
revertReason, err := revertreason.GetRevertReason(client, txHash)
t.Log(revertReason)
assert.Equal(t, err, nil)
assert.Equal(t, revertReason, "execution reverted: 1")
// This transaction success
revertReason, err = revertreason.GetRevertReason(client, common.HexToHash("0x1eb9e64dca2c8bfd62a11f2a67172b2cbc4f4286f034dcd96f079918bc50d44f"))
assert.Equal(t, err, nil)
assert.Equal(t, revertReason, "")
}