Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed Sep 25, 2023
1 parent c17202f commit d551723
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 40 deletions.
38 changes: 29 additions & 9 deletions tests/e2e/p/warp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ import (
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/testnet"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/example/xsvm/cmd/issue/export"
"github.com/ava-labs/avalanchego/vms/example/xsvm/cmd/issue/importtx"
"github.com/ava-labs/avalanchego/vms/example/xsvm/cmd/issue/transfer"
"github.com/ava-labs/avalanchego/vms/example/xsvm/genesis"
"github.com/ava-labs/avalanchego/wallet/chain/p"
)

var _ = e2e.DescribePChain("[Warp]", func() {
Expand Down Expand Up @@ -52,13 +55,11 @@ var _ = e2e.DescribePChain("[Warp]", func() {
},
})
require.NoError(err)
blockchainSpec := testnet.BlockchainSpec{
VMName: "xsvm",
Genesis: genesisBytes,
}
subnetSpec := testnet.SubnetSpec{
Blockchains: []testnet.BlockchainSpec{
{
VMName: "xsvm",
Genesis: genesisBytes,
},
},
Nodes: []testnet.NodeSpec{
{
Flags: testnet.FlagsMap{
Expand All @@ -78,18 +79,19 @@ var _ = e2e.DescribePChain("[Warp]", func() {
pWallet,
privateKey.Address(),
network,
e2e.RegisterNodeforCleanup,
nil, //e2e.RegisterNodeforCleanup,
subnetSpec,
subnetSpec,
)
require.NoError(err)

sourceSubnet := subnets[0]
sourceChainID := sourceSubnet.BlockchainIDs[0]
sourceChainID := createBlockchain(pWallet, sourceSubnet.ID, blockchainSpec)
destinationSubnet := subnets[1]
destinationChainID := destinationSubnet.BlockchainIDs[0]
destinationChainID := createBlockchain(pWallet, destinationSubnet.ID, blockchainSpec)

ginkgo.By(fmt.Sprintf("exporting from blockchain %s on subnet %s", sourceChainID, sourceSubnet.ID))
tests.Outf(" export will be on node %s for URI %s", sourceSubnet.Nodes[0].GetID(), sourceSubnet.Nodes[0].GetProcessContext().URI)
exportTxStatus, err := export.Export(
e2e.DefaultContext(),
&export.Config{
Expand Down Expand Up @@ -141,3 +143,21 @@ var _ = e2e.DescribePChain("[Warp]", func() {
// TODO(marun) Verify the balances on both chains
})
})

func createBlockchain(pWallet p.Wallet, subnetID ids.ID, blockchainSpec testnet.BlockchainSpec) ids.ID {
require := require.New(ginkgo.GinkgoT())

ginkgo.By(fmt.Sprintf("creating blockchain on subnet %s\n", subnetID))
vmID, err := testnet.GetVMID(blockchainSpec.VMName)
require.NoError(err)
createChainTx, err := pWallet.IssueCreateChainTx(
subnetID,
blockchainSpec.Genesis,
vmID,
nil,
blockchainSpec.VMName,
e2e.WithDefaultContext(),
)
require.NoError(err)
return createChainTx.ID()
}
55 changes: 24 additions & 31 deletions tests/fixture/testnet/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/fixture/testnet/local"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/set"
Expand Down Expand Up @@ -62,9 +63,25 @@ type NodeSpec struct {

// Collects the result of subnet creation
type CreatedSubnet struct {
ID ids.ID
ID ids.ID
PrivateKey
BlockchainIDs []ids.ID
Nodes []Node
NodePaths []string
nodes []Node
}

func (s *CreatedSubnet) GetNodes() ([]Nodes, error) {
if s.nodes == nil {
nodes = make([]Node, len(s.NodePaths))
for i, path := range s.NodePaths {
nodes[i], err = local.ReadNode(path)
if err != nil {
return nil, err
}
}
s.nodes = nodes
}
return s.nodes, nil
}

func GetVMID(vmName string) (ids.ID, error) {
Expand Down Expand Up @@ -195,31 +212,6 @@ func CreateSubnet(
}
subnetID := subnetTx.ID()

blockchainIDs := make([]ids.ID, len(spec.Blockchains))
for i, blockchainSpec := range spec.Blockchains {
if _, err := fmt.Fprintf(w, "creating blockchain on subnet %s\n", subnetID); err != nil {
return nil, err
}
vmID, err := GetVMID(blockchainSpec.VMName)
if err != nil {
return nil, fmt.Errorf("failed to determine VM ID for blockchain: %w", err)
}
ctx, cancel := context.WithTimeout(rootContext, txTimeout)
defer cancel()
createChainTx, err := pWallet.IssueCreateChainTx(
subnetID,
blockchainSpec.Genesis,
vmID,
nil,
blockchainSpec.VMName,
common.WithContext(ctx),
)
if err != nil {
return nil, fmt.Errorf("failed to create blockchain: %w", err)
}
blockchainIDs[i] = createChainTx.ID()
}

if _, err := fmt.Fprintf(w, "creating nodes for subnet %s\n", subnetID); err != nil {
return nil, err
}
Expand All @@ -233,7 +225,9 @@ func CreateSubnet(
if err != nil {
return nil, err
}
nodeCleanupFunc(node)
if nodeCleanupFunc != nil {
nodeCleanupFunc(node)
}
allNodes = append(allNodes, node)
}
}
Expand Down Expand Up @@ -315,9 +309,8 @@ func CreateSubnet(
}

return &CreatedSubnet{
ID: subnetID,
BlockchainIDs: blockchainIDs,
Nodes: allNodes,
ID: subnetID,
Nodes: allNodes,
}, nil
}

Expand Down

0 comments on commit d551723

Please sign in to comment.