-
Notifications
You must be signed in to change notification settings - Fork 672
/
suites.go
147 lines (125 loc) · 4.06 KB
/
suites.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Implements tests for the banff network upgrade.
package banff
import (
"context"
ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/e2e"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/components/verify"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
)
var _ = ginkgo.Describe("[Banff]", func() {
ginkgo.It("can send custom assets X->P and P->X",
// use this for filtering tests by labels
// ref. https://onsi.github.io/ginkgo/#spec-labels
ginkgo.Label(
"require-network-runner",
"xp",
"banff",
),
func() {
ginkgo.By("reload initial snapshot for test independence", func() {
err := e2e.Env.RestoreInitialState(true /*switchOffNetworkFirst*/)
gomega.Expect(err).Should(gomega.BeNil())
})
uris := e2e.Env.GetURIs()
gomega.Expect(uris).ShouldNot(gomega.BeEmpty())
kc := secp256k1fx.NewKeychain(genesis.EWOQKey)
var wallet primary.Wallet
ginkgo.By("initialize wallet", func() {
walletURI := uris[0]
// 5-second is enough to fetch initial UTXOs for test cluster in "primary.NewWallet"
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultWalletCreationTimeout)
var err error
wallet, err = primary.NewWalletFromURI(ctx, walletURI, kc)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}}created wallet{{/}}\n")
})
// Get the P-chain and the X-chain wallets
pWallet := wallet.P()
xWallet := wallet.X()
// Pull out useful constants to use when issuing transactions.
xChainID := xWallet.BlockchainID()
owner := &secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{
genesis.EWOQKey.PublicKey().Address(),
},
}
var assetID ids.ID
ginkgo.By("create new X-chain asset", func() {
var err error
assetID, err = xWallet.IssueCreateAssetTx(
"RnM",
"RNM",
9,
map[uint32][]verify.State{
0: {
&secp256k1fx.TransferOutput{
Amt: 100 * units.Schmeckle,
OutputOwners: *owner,
},
},
},
)
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}}created new X-chain asset{{/}}: %s\n", assetID)
})
ginkgo.By("export new X-chain asset to P-chain", func() {
txID, err := xWallet.IssueExportTx(
constants.PlatformChainID,
[]*avax.TransferableOutput{
{
Asset: avax.Asset{
ID: assetID,
},
Out: &secp256k1fx.TransferOutput{
Amt: 100 * units.Schmeckle,
OutputOwners: *owner,
},
},
},
)
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}}issued X-chain export{{/}}: %s\n", txID)
})
ginkgo.By("import new asset from X-chain on the P-chain", func() {
txID, err := pWallet.IssueImportTx(xChainID, owner)
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}}issued P-chain import{{/}}: %s\n", txID)
})
ginkgo.By("export asset from P-chain to the X-chain", func() {
txID, err := pWallet.IssueExportTx(
xChainID,
[]*avax.TransferableOutput{
{
Asset: avax.Asset{
ID: assetID,
},
Out: &secp256k1fx.TransferOutput{
Amt: 100 * units.Schmeckle,
OutputOwners: *owner,
},
},
},
)
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}}issued P-chain export{{/}}: %s\n", txID)
})
ginkgo.By("import asset from P-chain on the X-chain", func() {
txID, err := xWallet.IssueImportTx(constants.PlatformChainID, owner)
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}}issued X-chain import{{/}}: %s\n", txID)
})
})
})