-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dhruba Basu <[email protected]> Co-authored-by: Stephen Buttolph <[email protected]>
- Loading branch information
1 parent
d3c09eb
commit ccf2612
Showing
25 changed files
with
1,395 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package p | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ava-labs/avalanchego/api/info" | ||
"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/vms/platformvm" | ||
"github.com/ava-labs/avalanchego/vms/secp256k1fx" | ||
|
||
ginkgo "github.com/onsi/ginkgo/v2" | ||
) | ||
|
||
var _ = e2e.DescribePChain("[Permissionless L1]", func() { | ||
tc := e2e.NewTestContext() | ||
require := require.New(tc) | ||
|
||
ginkgo.It("creates a Permissionless L1", func() { | ||
env := e2e.GetEnv(tc) | ||
nodeURI := env.GetRandomNodeURI() | ||
infoClient := info.NewClient(nodeURI.URI) | ||
|
||
tc.By("fetching upgrade config") | ||
upgrades, err := infoClient.Upgrades(tc.DefaultContext()) | ||
require.NoError(err) | ||
|
||
tc.By("verifying Etna is activated") | ||
now := time.Now() | ||
if !upgrades.IsEtnaActivated(now) { | ||
ginkgo.Skip("Etna is not activated. Permissionless L1s are enabled post-Etna, skipping test.") | ||
} | ||
|
||
keychain := env.NewKeychain() | ||
baseWallet := e2e.NewWallet(tc, keychain, nodeURI) | ||
|
||
pWallet := baseWallet.P() | ||
pClient := platformvm.NewClient(nodeURI.URI) | ||
|
||
owner := &secp256k1fx.OutputOwners{ | ||
Threshold: 1, | ||
Addrs: []ids.ShortID{ | ||
keychain.Keys[0].Address(), | ||
}, | ||
} | ||
|
||
tc.By("issuing a CreateSubnetTx") | ||
subnetTx, err := pWallet.IssueCreateSubnetTx( | ||
owner, | ||
tc.WithDefaultContext(), | ||
) | ||
require.NoError(err) | ||
|
||
tc.By("verifying a Permissioned Subnet was successfully created") | ||
subnetID := subnetTx.ID() | ||
require.NotEqual(subnetID, constants.PrimaryNetworkID) | ||
|
||
res, err := pClient.GetSubnet(tc.DefaultContext(), subnetID) | ||
require.NoError(err) | ||
|
||
require.Equal(platformvm.GetSubnetClientResponse{ | ||
IsPermissioned: true, | ||
ControlKeys: []ids.ShortID{ | ||
keychain.Keys[0].Address(), | ||
}, | ||
Threshold: 1, | ||
}, res) | ||
|
||
chainID := ids.GenerateTestID() | ||
address := []byte{'a', 'd', 'd', 'r', 'e', 's', 's'} | ||
|
||
tc.By("issuing a ConvertSubnetTx") | ||
_, err = pWallet.IssueConvertSubnetTx( | ||
subnetID, | ||
chainID, | ||
address, | ||
tc.WithDefaultContext(), | ||
) | ||
require.NoError(err) | ||
|
||
tc.By("verifying the Permissioned Subnet was converted to a Permissionless L1") | ||
res, err = pClient.GetSubnet(tc.DefaultContext(), subnetID) | ||
require.NoError(err) | ||
|
||
require.Equal(platformvm.GetSubnetClientResponse{ | ||
IsPermissioned: false, | ||
ControlKeys: []ids.ShortID{ | ||
keychain.Keys[0].Address(), | ||
}, | ||
Threshold: 1, | ||
ManagerChainID: chainID, | ||
ManagerAddress: address, | ||
}, res) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package txs | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/snow" | ||
"github.com/ava-labs/avalanchego/utils/constants" | ||
"github.com/ava-labs/avalanchego/vms/components/verify" | ||
"github.com/ava-labs/avalanchego/vms/types" | ||
) | ||
|
||
const MaxSubnetAddressLength = 4096 | ||
|
||
var ( | ||
_ UnsignedTx = (*TransferSubnetOwnershipTx)(nil) | ||
|
||
ErrConvertPermissionlessSubnet = errors.New("cannot convert a permissionless subnet") | ||
ErrAddressTooLong = errors.New("address is too long") | ||
) | ||
|
||
type ConvertSubnetTx struct { | ||
// Metadata, inputs and outputs | ||
BaseTx `serialize:"true"` | ||
// ID of the Subnet to transform | ||
Subnet ids.ID `serialize:"true" json:"subnetID"` | ||
// Chain where the Subnet manager lives | ||
ChainID ids.ID `serialize:"true" json:"chainID"` | ||
// Address of the Subnet manager | ||
Address types.JSONByteSlice `serialize:"true" json:"address"` | ||
// Authorizes this conversion | ||
SubnetAuth verify.Verifiable `serialize:"true" json:"subnetAuthorization"` | ||
} | ||
|
||
func (tx *ConvertSubnetTx) SyntacticVerify(ctx *snow.Context) error { | ||
switch { | ||
case tx == nil: | ||
return ErrNilTx | ||
case tx.SyntacticallyVerified: | ||
// already passed syntactic verification | ||
return nil | ||
case tx.Subnet == constants.PrimaryNetworkID: | ||
return ErrConvertPermissionlessSubnet | ||
case len(tx.Address) > MaxSubnetAddressLength: | ||
return ErrAddressTooLong | ||
} | ||
|
||
if err := tx.BaseTx.SyntacticVerify(ctx); err != nil { | ||
return err | ||
} | ||
if err := tx.SubnetAuth.Verify(); err != nil { | ||
return err | ||
} | ||
|
||
tx.SyntacticallyVerified = true | ||
return nil | ||
} | ||
|
||
func (tx *ConvertSubnetTx) Visit(visitor Visitor) error { | ||
return visitor.ConvertSubnetTx(tx) | ||
} |
Oops, something went wrong.