-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutils_test.go
92 lines (70 loc) · 2.78 KB
/
utils_test.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package sequence_test
import (
"context"
"testing"
"github.com/0xsequence/ethkit/ethwallet"
"github.com/0xsequence/ethkit/go-ethereum/core/types"
"github.com/0xsequence/go-sequence"
v1 "github.com/0xsequence/go-sequence/core/v1"
v2 "github.com/0xsequence/go-sequence/core/v2"
"github.com/0xsequence/go-sequence/testutil"
"github.com/stretchr/testify/assert"
)
func TestDeploySequenceWallet(t *testing.T) {
t.Run("v1", func(t *testing.T) {
// Create new single owner smart wallet (initially undeployed, of course)
eoa, err := ethwallet.NewWalletFromRandomEntropy()
assert.NoError(t, err)
wallet, err := sequence.GenericNewWalletSingleOwner[*v1.WalletConfig](eoa, testutil.V1SequenceContext())
assert.NoError(t, err)
wallet.SetProvider(testChain.Provider)
chainID := wallet.GetChainID()
assert.Equal(t, uint64(1337), chainID.Uint64())
// Confirm the wallet is not deployed
isDeployed, err := wallet.IsDeployed()
if err != nil {
t.Fatalf("wallet is deployed, but expecting it to be undeployed")
}
assert.False(t, isDeployed)
relayWallet := testChain.GetRelayerWallet()
walletAddress, tx, waitReceipt, err := sequence.DeploySequenceWallet(relayWallet, wallet.GetWalletConfig(), wallet.GetWalletContext())
assert.NoError(t, err)
assert.NotNil(t, tx)
receipt, err := waitReceipt(context.Background())
assert.NoError(t, err)
assert.True(t, receipt.Status == types.ReceiptStatusSuccessful)
// Confirm wallet is now deployed
isDeployed, err = wallet.IsDeployed()
assert.NoError(t, err)
assert.True(t, isDeployed)
assert.Equal(t, wallet.Address(), walletAddress)
})
t.Run("v2", func(t *testing.T) {
// Create new single owner smart wallet (initially undeployed, of course)
eoa, err := ethwallet.NewWalletFromRandomEntropy()
assert.NoError(t, err)
wallet, err := sequence.GenericNewWalletSingleOwner[*v2.WalletConfig](eoa, testutil.V2SequenceContext())
assert.NoError(t, err)
wallet.SetProvider(testChain.Provider)
chainID := wallet.GetChainID()
assert.Equal(t, uint64(1337), chainID.Uint64())
// Confirm the wallet is not deployed
isDeployed, err := wallet.IsDeployed()
if err != nil {
t.Fatalf("wallet is deployed, but expecting it to be undeployed")
}
assert.False(t, isDeployed)
relayWallet := testChain.GetRelayerWallet()
walletAddress, tx, waitReceipt, err := sequence.DeploySequenceWallet(relayWallet, wallet.GetWalletConfig(), wallet.GetWalletContext())
assert.NoError(t, err)
assert.NotNil(t, tx)
receipt, err := waitReceipt(context.Background())
assert.NoError(t, err)
assert.True(t, receipt.Status == types.ReceiptStatusSuccessful)
// Confirm wallet is now deployed
isDeployed, err = wallet.IsDeployed()
assert.NoError(t, err)
assert.True(t, isDeployed)
assert.Equal(t, wallet.Address(), walletAddress)
})
}