Skip to content

Commit

Permalink
Merge #1478
Browse files Browse the repository at this point in the history
1478: add func to set approved nodes list r=kc1116 a=kc1116

This PR adds a util func to add a node to the approved nodes list. It allows epoch join tests to better mimic the process that happens when a new node is onboarded. 

Co-authored-by: Khalil Claybon <khalil.claybon@dapperlabs.com>
  • Loading branch information
bors[bot] and kc1116 committed Oct 19, 2021
2 parents 674122b + c196885 commit 4233145
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
18 changes: 16 additions & 2 deletions integration/tests/epochs/epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,22 @@ func (s *Suite) TestEpochJoin() {
require.True(s.T(), ok)

// make sure node info we generated matches what we get from the flow staking table
nodeID := string(nodeInfo.Fields[0].(cadence.String))
require.Equal(s.T(), info.NodeID.String(), nodeID, "expected generated in test to equal node ID node ID from staking table ")
nodeIDFromState := string(nodeInfo.Fields[0].(cadence.String))
require.Equal(s.T(), info.NodeID.String(), nodeIDFromState, "expected node ID generated in test to equal node ID from staking table ")

result := s.SetApprovedNodesScript(ctx, env, append(s.net.Identities().NodeIDs(), info.NodeID)...)
require.NoError(s.T(), result.Error)

// get new approved nodes list and make sure new node was added correctly
approvedNodes := s.ExecuteReadApprovedNodesScript(ctx, env)

found := false
for _, val := range approvedNodes.(cadence.Array).Values {
if string(val.(cadence.String)) == info.NodeID.String() {
found = true
}
}

require.True(s.T(), found, "node id for new node not found in approved list after setting the approved list")
s.net.StopContainers()
}
43 changes: 43 additions & 0 deletions integration/tests/epochs/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,46 @@ func (s *Suite) ExecuteGetNodeInfoScript(ctx context.Context, env templates.Envi

return v
}

// SetApprovedNodesScript adds a node the the approved node list, this must be done when a node joins the protocol during the epoch staking phase
func (s *Suite) SetApprovedNodesScript(ctx context.Context, env templates.Environment, identities ...flow.Identifier) *sdk.TransactionResult {
ids := make([]cadence.Value, 0)
for _, id := range identities {
idCDC, err := cadence.NewString(id.String())
require.NoError(s.T(), err)

ids = append(ids, idCDC)
}

latestBlockID, err := s.client.GetLatestBlockID(ctx)
require.NoError(s.T(), err)


idTableAddress := sdk.HexToAddress(env.IDTableAddress)
tx := sdk.NewTransaction().
SetScript(templates.GenerateSetApprovedNodesScript(env)).
SetGasLimit(9999).
SetReferenceBlockID(sdk.Identifier(latestBlockID)).
SetProposalKey(s.client.SDKServiceAddress(), 0, s.client.Account().Keys[0].SequenceNumber).
SetPayer(s.client.SDKServiceAddress()).
AddAuthorizer(idTableAddress)

err = tx.AddArgument(cadence.NewArray(ids))
require.NoError(s.T(), err)

err = s.client.SignAndSendTransaction(ctx, tx)
require.NoError(s.T(), err)

result, err := s.client.WaitForSealed(ctx, tx.ID())
require.NoError(s.T(), err)

return result
}

// ExecuteReadApprovedNodesScript executes the return proposal table script and returns a list of approved nodes
func (s *Suite) ExecuteReadApprovedNodesScript(ctx context.Context, env templates.Environment) cadence.Value {
v, err := s.client.ExecuteScriptBytes(ctx, templates.GenerateReturnProposedTableScript(env), []cadence.Value{})
require.NoError(s.T(), err)

return v
}

0 comments on commit 4233145

Please sign in to comment.