diff --git a/integration/tests/upgrades/protocol_version_upgrade_test.go b/integration/tests/upgrades/protocol_version_upgrade_test.go index 2a23fd55c05..c42f64702cf 100644 --- a/integration/tests/upgrades/protocol_version_upgrade_test.go +++ b/integration/tests/upgrades/protocol_version_upgrade_test.go @@ -27,17 +27,13 @@ func TestProtocolVersionUpgrade(t *testing.T) { suite.Run(t, new(ProtocolVersionUpgradeSuite)) } -func (suite *ProtocolVersionUpgradeSuite) SetupTest() { - suite.Suite.SetupTest() +func (s *ProtocolVersionUpgradeSuite) SetupTest() { // Begin the test with a v0 kvstore, rather than the default v1. // This lets us test upgrading v0->v1 - protocolState, err := suite.net.BootstrapSnapshot.ProtocolState() - require.NoError(suite.T(), err) - finalizationThreshold := protocolState.GetFinalizationSafetyThreshold() - epochExtensionViewCount := protocolState.GetEpochExtensionViewCount() - suite.KVStoreFactory = func(epochStateID flow.Identifier) (protocol_state.KVStoreAPI, error) { - return kvstore.NewKVStoreV0(finalizationThreshold, epochExtensionViewCount, epochStateID) + s.KVStoreFactory = func(epochStateID flow.Identifier) (protocol_state.KVStoreAPI, error) { + return kvstore.NewKVStoreV0(5, 100, epochStateID) } + s.Suite.SetupTest() } // TestProtocolStateVersionUpgradeServiceEvent tests the process of upgrading the protocol diff --git a/integration/utils/templates/set-protocol-state-version.cdc b/integration/utils/templates/set-protocol-state-version.cdc new file mode 100644 index 00000000000..0dd86c4eb61 --- /dev/null +++ b/integration/utils/templates/set-protocol-state-version.cdc @@ -0,0 +1,29 @@ +import NodeVersionBeacon from "NodeVersionBeacon" + +/// Transaction that allows NodeVersionAdmin to specify a new protocol state version. +/// The new version will become active at view `activeView` if the service event +/// is processed and applied to the protocol state within a block `B` such that +/// `B.view + ∆ < activeView`, for a protocol-defined safety threshold ∆. +/// Service events not meeting this threshold are discarded. +/// +/// This is a special version of the admin transaction for use in integration tests. +/// We allow the sender to pass in a value to add to the current view, to reduce +/// the liklihood that a test spuriously fails due to timing. +transaction(newProtocolVersion: UInt64, activeViewDiff: UInt64) { + + let adminRef: &NodeVersionBeacon.Admin + + prepare(acct: auth(BorrowValue) &Account) { + // Borrow a reference to the NodeVersionAdmin implementing resource + self.adminRef = acct.storage.borrow<&NodeVersionBeacon.Admin>(from: NodeVersionBeacon.AdminStoragePath) + ?? panic("Couldn't borrow NodeVersionBeacon.Admin Resource") + } + + execute { + let block = getCurrentBlock() + self.adminRef.emitProtocolStateVersionUpgrade( + newProtocolVersion: newProtocolVersion, + activeView: block.view + activeViewDiff + ) + } +} diff --git a/integration/utils/transactions.go b/integration/utils/transactions.go index 1b687491b6b..6edd8d510ce 100644 --- a/integration/utils/transactions.go +++ b/integration/utils/transactions.go @@ -24,6 +24,9 @@ var createAndSetupNodeTxScript string //go:embed templates/remove-node.cdc var removeNodeTxScript string +//go:embed "templates/set-protocol-state-version.cdc" +var setProtocolStateVersionScript string + func LocalnetEnv() templates.Environment { return templates.Environment{ EpochAddress: "f8d6e0586b0a20c7", @@ -194,7 +197,7 @@ func MakeSetProtocolStateVersionTx( accountKey := adminAccount.Keys[adminAccountKeyID] tx := sdk.NewTransaction(). - SetScript(templates.GenerateSetProtocolStateVersionScript(env)). + SetScript([]byte(templates.ReplaceAddresses(setProtocolStateVersionScript, env))). SetComputeLimit(9999). SetReferenceBlockID(latestBlockID). SetProposalKey(adminAccount.Address, adminAccountKeyID, accountKey.SequenceNumber).