-
Notifications
You must be signed in to change notification settings - Fork 665
/
permissionless_subnets.go
200 lines (182 loc) · 5.81 KB
/
permissionless_subnets.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package p
import (
"context"
"fmt"
"time"
ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/ava-labs/avalanchego/ids"
"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/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
)
var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
ginkgo.It("subnets operations",
// use this for filtering tests by labels
// ref. https://onsi.github.io/ginkgo/#spec-labels
ginkgo.Label(
"xp",
"permissionless-subnets",
),
func() {
nodeURI := e2e.Env.GetRandomNodeURI()
keychain := e2e.Env.NewKeychain(1)
baseWallet := e2e.Env.NewWallet(keychain, nodeURI)
pWallet := baseWallet.P()
xWallet := baseWallet.X()
xChainID := xWallet.BlockchainID()
var validatorID ids.NodeID
ginkgo.By("retrieving the node ID of a primary network validator", func() {
pChainClient := platformvm.NewClient(nodeURI.URI)
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
validatorIDs, err := pChainClient.SampleValidators(ctx, constants.PrimaryNetworkID, 1)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(validatorIDs).Should(gomega.HaveLen(1))
validatorID = validatorIDs[0]
})
owner := &secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{
keychain.Keys[0].Address(),
},
}
var subnetID ids.ID
ginkgo.By("create a permissioned subnet", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
subnetTx, err := pWallet.IssueCreateSubnetTx(
owner,
common.WithContext(ctx),
)
cancel()
subnetID = subnetTx.ID()
gomega.Expect(subnetID, err).Should(gomega.Not(gomega.Equal(constants.PrimaryNetworkID)))
})
var subnetAssetID ids.ID
ginkgo.By("create a custom asset for the permissionless subnet", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
subnetAssetTx, err := xWallet.IssueCreateAssetTx(
"RnM",
"RNM",
9,
map[uint32][]verify.State{
0: {
&secp256k1fx.TransferOutput{
Amt: 100 * units.MegaAvax,
OutputOwners: *owner,
},
},
},
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
subnetAssetID = subnetAssetTx.ID()
})
ginkgo.By(fmt.Sprintf("Send 100 MegaAvax of asset %s to the P-chain", subnetAssetID), func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
_, err := xWallet.IssueExportTx(
constants.PlatformChainID,
[]*avax.TransferableOutput{
{
Asset: avax.Asset{
ID: subnetAssetID,
},
Out: &secp256k1fx.TransferOutput{
Amt: 100 * units.MegaAvax,
OutputOwners: *owner,
},
},
},
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})
ginkgo.By(fmt.Sprintf("Import the 100 MegaAvax of asset %s from the X-chain into the P-chain", subnetAssetID), func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
_, err := pWallet.IssueImportTx(
xChainID,
owner,
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})
ginkgo.By("make subnet permissionless", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
_, err := pWallet.IssueTransformSubnetTx(
subnetID,
subnetAssetID,
50*units.MegaAvax,
100*units.MegaAvax,
reward.PercentDenominator,
reward.PercentDenominator,
1,
100*units.MegaAvax,
time.Second,
365*24*time.Hour,
0,
1,
5,
.80*reward.PercentDenominator,
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})
validatorStartTime := time.Now().Add(time.Minute)
ginkgo.By("add permissionless validator", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
_, err := pWallet.IssueAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: validatorID,
Start: uint64(validatorStartTime.Unix()),
End: uint64(validatorStartTime.Add(5 * time.Second).Unix()),
Wght: 25 * units.MegaAvax,
},
Subnet: subnetID,
},
&signer.Empty{},
subnetAssetID,
&secp256k1fx.OutputOwners{},
&secp256k1fx.OutputOwners{},
reward.PercentDenominator,
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})
delegatorStartTime := validatorStartTime
ginkgo.By("add permissionless delegator", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
_, err := pWallet.IssueAddPermissionlessDelegatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: validatorID,
Start: uint64(delegatorStartTime.Unix()),
End: uint64(delegatorStartTime.Add(5 * time.Second).Unix()),
Wght: 25 * units.MegaAvax,
},
Subnet: subnetID,
},
subnetAssetID,
&secp256k1fx.OutputOwners{},
common.WithContext(ctx),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})
})
})