forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suites.go
131 lines (114 loc) · 3.26 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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Implements tests for the banff network upgrade.
package banff
import (
"github.com/onsi/ginkgo/v2"
"github.com/stretchr/testify/require"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/fixture/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"
)
var _ = ginkgo.Describe("[Banff]", func() {
tc := e2e.NewTestContext()
require := require.New(tc)
ginkgo.It("can send custom assets X->P and P->X",
func() {
env := e2e.GetEnv(tc)
keychain := env.NewKeychain()
wallet := e2e.NewWallet(tc, keychain, env.GetRandomNodeURI())
// Get the P-chain and the X-chain wallets
pWallet := wallet.P()
xWallet := wallet.X()
xBuilder := xWallet.Builder()
xContext := xBuilder.Context()
// Pull out useful constants to use when issuing transactions.
xChainID := xContext.BlockchainID
owner := &secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{
keychain.Keys[0].Address(),
},
}
var assetID ids.ID
tc.By("create new X-chain asset", func() {
assetTx, err := xWallet.IssueCreateAssetTx(
"RnM",
"RNM",
9,
map[uint32][]verify.State{
0: {
&secp256k1fx.TransferOutput{
Amt: 100 * units.Schmeckle,
OutputOwners: *owner,
},
},
},
tc.WithDefaultContext(),
)
require.NoError(err)
assetID = assetTx.ID()
tc.Outf("{{green}}created new X-chain asset{{/}}: %s\n", assetID)
})
tc.By("export new X-chain asset to P-chain", func() {
tx, err := xWallet.IssueExportTx(
constants.PlatformChainID,
[]*avax.TransferableOutput{
{
Asset: avax.Asset{
ID: assetID,
},
Out: &secp256k1fx.TransferOutput{
Amt: 100 * units.Schmeckle,
OutputOwners: *owner,
},
},
},
tc.WithDefaultContext(),
)
require.NoError(err)
tc.Outf("{{green}}issued X-chain export{{/}}: %s\n", tx.ID())
})
tc.By("import new asset from X-chain on the P-chain", func() {
tx, err := pWallet.IssueImportTx(
xChainID,
owner,
tc.WithDefaultContext(),
)
require.NoError(err)
tc.Outf("{{green}}issued P-chain import{{/}}: %s\n", tx.ID())
})
tc.By("export asset from P-chain to the X-chain", func() {
tx, err := pWallet.IssueExportTx(
xChainID,
[]*avax.TransferableOutput{
{
Asset: avax.Asset{
ID: assetID,
},
Out: &secp256k1fx.TransferOutput{
Amt: 100 * units.Schmeckle,
OutputOwners: *owner,
},
},
},
tc.WithDefaultContext(),
)
require.NoError(err)
tc.Outf("{{green}}issued P-chain export{{/}}: %s\n", tx.ID())
})
tc.By("import asset from P-chain on the X-chain", func() {
tx, err := xWallet.IssueImportTx(
constants.PlatformChainID,
owner,
tc.WithDefaultContext(),
)
require.NoError(err)
tc.Outf("{{green}}issued X-chain import{{/}}: %s\n", tx.ID())
})
})
})