ava-labs / avalanchego-kurtosis

Run AvalancheGo tests in the Kurtosis framework
BSD 3-Clause "New" or "Revised" License
3 stars 8 forks source link

FR: networkbuilder has a `Build` method that produces an AvalancheNetwork #4

Open mieubrisse opened 3 years ago

mieubrisse commented 3 years ago

This would eliminate the need for the following code in the Setup method of AvalancheTestRunner:

    // first setup bootstrap nodes
    var nodeChecker []*services.DefaultAvailabilityChecker
    for i := 1; i <= runner.definedNetwork.GetNumBootstrapNodes(); i++ {
        if bootstrapNode, ok := runner.definedNetwork.Nodes[fmt.Sprintf("bootstrapNode-%d", i)]; ok {
            if bootstrapNode.IsBootstrapNode() {
                _, checker, err := newNetwork.CreateNodeNoCheck(runner.definedNetwork, bootstrapNode)
                if err != nil {
                    return nil, stacktrace.Propagate(err, "An error occurred creating a new Node")
                }
                nodeChecker = append(nodeChecker, checker)
            }
        }
    }

    for _, checker := range nodeChecker {
        err := checker.WaitForStartup(15*time.Second, 10)
        if err != nil {
            panic(err)
        }
    }

    for _, node := range runner.definedNetwork.Nodes {
        if !node.IsBootstrapNode() {
            _, err := newNetwork.CreateNode(runner.definedNetwork, node)
            if err != nil {
                return nil, stacktrace.Propagate(err, "An error occurred creating a new Node")
            }
        }
    }

This would also make Avalanche network-building standalone, so users could write their own tests without needing to use AvalancheTestRunner like so:

func (test SmartContractTest) Setup(networkCtx *networks.NetworkContext) (networks.Network, error) {
    txFee := testconstants.TxFee
    totalAmount := testconstants.TotalAmount
    seedAmount := testconstants.SeedAmount
    stakeAmount := testconstants.StakeAmount
    validatorNodeName := testconstants.ValidatorNodeName
    stakerUsername := testconstants.StakerUsername
    stakerPassword := testconstants.StakerPassword
    delegatorNodeName := testconstants.DelegatorNodeName
    delegatorUsername := testconstants.DelegatorUsername
    delegatorPassword := testconstants.DelegatorPassword
    genesisUsername := testconstants.GenesisUsername
    genesisPassword := testconstants.GenesisPassword

    // create the nodes
    stakerNode := networkbuilder.NewNode(testconstants.ValidatorNodeName).
        Image(test.avalancheImage).
        IsStaking(true)

    delegatorNode := networkbuilder.NewNode(testconstants.DelegatorNodeName).
        Image(test.avalancheImage).
        IsStaking(true)

    definedNetwork := scenarios.NewBootStrappingNodeNetwork(test.avalancheImage).
        TxFee(txFee).
        AddNode(stakerNode).
        AddNode(delegatorNode)

        return definedNetwork.build()   // Doesn't exist yet
}
mieubrisse commented 3 years ago

This would also mean that AvalancheNetwork.CreateNode wouldn't need to take in the builder, so that a Test.Run method could call AddNode (right now it can't due to needing the builder)

otherview commented 3 years ago

Would this mean that the builder now would create the Nodes ?

What would a test look like ?