Skip to content

Commit

Permalink
Merge #4142
Browse files Browse the repository at this point in the history
4142: Move test fixtures closer to usage r=janezpodhostnik a=janezpodhostnik

Extracting pieces from #3736 so its easier to digest and merge.

Co-authored-by: Janez Podhostnik <janez.podhostnik@gmail.com>
  • Loading branch information
bors[bot] and janezpodhostnik authored Apr 3, 2023
2 parents ae79b52 + c5439c7 commit a525801
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
5 changes: 2 additions & 3 deletions engine/execution/computation/computer/computer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"github.com/onflow/flow-go/fvm/storage/testutils"
"github.com/onflow/flow-go/fvm/systemcontracts"
"github.com/onflow/flow-go/ledger"
"github.com/onflow/flow-go/model/convert/fixtures"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/epochs"
"github.com/onflow/flow-go/module/executiondatasync/execution_data"
Expand Down Expand Up @@ -553,7 +552,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
serviceEvents, err := systemcontracts.ServiceEventsForChain(execCtx.Chain.ChainID())
require.NoError(t, err)

payload, err := json.Decode(nil, []byte(fixtures.EpochSetupFixtureJSON))
payload, err := json.Decode(nil, []byte(unittest.EpochSetupFixtureJSON))
require.NoError(t, err)

serviceEventA, ok := payload.(cadence.Event)
Expand All @@ -564,7 +563,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
}
serviceEventA.EventType.QualifiedIdentifier = serviceEvents.EpochSetup.QualifiedIdentifier()

payload, err = json.Decode(nil, []byte(fixtures.EpochCommitFixtureJSON))
payload, err = json.Decode(nil, []byte(unittest.EpochCommitFixtureJSON))
require.NoError(t, err)

serviceEventB, ok := payload.(cadence.Event)
Expand Down
6 changes: 3 additions & 3 deletions model/convert/service_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/stretchr/testify/require"

"github.com/onflow/flow-go/model/convert"
"github.com/onflow/flow-go/model/convert/fixtures"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/utils/unittest"
)

func TestEventConversion(t *testing.T) {
Expand All @@ -17,7 +17,7 @@ func TestEventConversion(t *testing.T) {

t.Run("epoch setup", func(t *testing.T) {

fixture, expected := fixtures.EpochSetupFixtureByChainID(chainID)
fixture, expected := unittest.EpochSetupFixtureByChainID(chainID)

// convert Cadence types to Go types
event, err := convert.ServiceEvent(chainID, fixture)
Expand All @@ -34,7 +34,7 @@ func TestEventConversion(t *testing.T) {

t.Run("epoch commit", func(t *testing.T) {

fixture, expected := fixtures.EpochCommitFixtureByChainID(chainID)
fixture, expected := unittest.EpochCommitFixtureByChainID(chainID)

// convert Cadence types to Go types
event, err := convert.ServiceEvent(chainID, fixture)
Expand Down
5 changes: 2 additions & 3 deletions module/chunks/chunkVerifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/onflow/flow-go/ledger/complete/wal/fixtures"
chunksmodels "github.com/onflow/flow-go/model/chunks"
"github.com/onflow/flow-go/model/convert"
convertfixtures "github.com/onflow/flow-go/model/convert/fixtures"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/verification"
"github.com/onflow/flow-go/module/chunks"
Expand All @@ -48,8 +47,8 @@ var eventsList = flow.EventsList{

// the chain we use for this test suite
var testChain = flow.Emulator
var epochSetupEvent, _ = convertfixtures.EpochSetupFixtureByChainID(testChain)
var epochCommitEvent, _ = convertfixtures.EpochCommitFixtureByChainID(testChain)
var epochSetupEvent, _ = unittest.EpochSetupFixtureByChainID(testChain)
var epochCommitEvent, _ = unittest.EpochCommitFixtureByChainID(testChain)

var epochSetupServiceEvent, _ = convert.ServiceEvent(testChain, epochSetupEvent)
var epochCommitServiceEvent, _ = convert.ServiceEvent(testChain, epochCommitEvent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package fixtures
package unittest

import (
"github.com/onflow/flow-go/crypto"
"github.com/onflow/flow-go/fvm/systemcontracts"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/utils/unittest"
)

// This file contains service event fixtures for testing purposes.
Expand All @@ -18,7 +17,7 @@ func EpochSetupFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.EpochSetu
panic(err)
}

event := unittest.EventFixture(events.EpochSetup.EventType(), 1, 1, unittest.IdentifierFixture(), 0)
event := EventFixture(events.EpochSetup.EventType(), 1, 1, IdentifierFixture(), 0)
event.Payload = []byte(EpochSetupFixtureJSON)

// randomSource is [0,0,...,1,2,3,4]
Expand Down Expand Up @@ -50,56 +49,56 @@ func EpochSetupFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.EpochSetu
Role: flow.RoleCollection,
NodeID: flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000001"),
Address: "1.flow.com",
NetworkPubKey: unittest.MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
StakingPubKey: unittest.MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
Weight: 100,
},
{
Role: flow.RoleCollection,
NodeID: flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000002"),
Address: "2.flow.com",
NetworkPubKey: unittest.MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
StakingPubKey: unittest.MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
Weight: 100,
},
{
Role: flow.RoleCollection,
NodeID: flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000003"),
Address: "3.flow.com",
NetworkPubKey: unittest.MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
StakingPubKey: unittest.MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
Weight: 100,
},
{
Role: flow.RoleCollection,
NodeID: flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000004"),
Address: "4.flow.com",
NetworkPubKey: unittest.MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
StakingPubKey: unittest.MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "378dbf45d85c614feb10d8bd4f78f4b6ef8eec7d987b937e123255444657fb3da031f232a507e323df3a6f6b8f50339c51d188e80c0e7a92420945cc6ca893fc"),
StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "af4aade26d76bb2ab15dcc89adcef82a51f6f04b3cb5f4555214b40ec89813c7a5f95776ea4fe449de48166d0bbc59b919b7eabebaac9614cf6f9461fac257765415f4d8ef1376a2365ec9960121888ea5383d88a140c24c29962b0a14e4e4e7"),
Weight: 100,
},
{
Role: flow.RoleConsensus,
NodeID: flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000011"),
Address: "11.flow.com",
NetworkPubKey: unittest.MustDecodePublicKeyHex(crypto.ECDSAP256, "cfdfe8e4362c8f79d11772cb7277ab16e5033a63e8dd5d34caf1b041b77e5b2d63c2072260949ccf8907486e4cfc733c8c42ca0e4e208f30470b0d950856cd47"),
StakingPubKey: unittest.MustDecodePublicKeyHex(crypto.BLSBLS12381, "8207559cd7136af378bba53a8f0196dee3849a3ab02897c1995c3e3f6ca0c4a776c3ae869d1ddbb473090054be2400ad06d7910aa2c5d1780220fdf3765a3c1764bce10c6fe66a5a2be51a422e878518bd750424bb56b8a0ecf0f8ad2057e83f"),
NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "cfdfe8e4362c8f79d11772cb7277ab16e5033a63e8dd5d34caf1b041b77e5b2d63c2072260949ccf8907486e4cfc733c8c42ca0e4e208f30470b0d950856cd47"),
StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "8207559cd7136af378bba53a8f0196dee3849a3ab02897c1995c3e3f6ca0c4a776c3ae869d1ddbb473090054be2400ad06d7910aa2c5d1780220fdf3765a3c1764bce10c6fe66a5a2be51a422e878518bd750424bb56b8a0ecf0f8ad2057e83f"),
Weight: 100,
},
{
Role: flow.RoleExecution,
NodeID: flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000021"),
Address: "21.flow.com",
NetworkPubKey: unittest.MustDecodePublicKeyHex(crypto.ECDSAP256, "d64318ba0dbf68f3788fc81c41d507c5822bf53154530673127c66f50fe4469ccf1a054a868a9f88506a8999f2386d86fcd2b901779718cba4fb53c2da258f9e"),
StakingPubKey: unittest.MustDecodePublicKeyHex(crypto.BLSBLS12381, "880b162b7ec138b36af401d07868cb08d25746d905395edbb4625bdf105d4bb2b2f4b0f4ae273a296a6efefa7ce9ccb914e39947ce0e83745125cab05d62516076ff0173ed472d3791ccef937597c9ea12381d76f547a092a4981d77ff3fba83"),
NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "d64318ba0dbf68f3788fc81c41d507c5822bf53154530673127c66f50fe4469ccf1a054a868a9f88506a8999f2386d86fcd2b901779718cba4fb53c2da258f9e"),
StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "880b162b7ec138b36af401d07868cb08d25746d905395edbb4625bdf105d4bb2b2f4b0f4ae273a296a6efefa7ce9ccb914e39947ce0e83745125cab05d62516076ff0173ed472d3791ccef937597c9ea12381d76f547a092a4981d77ff3fba83"),
Weight: 100,
},
{
Role: flow.RoleVerification,
NodeID: flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000031"),
Address: "31.flow.com",
NetworkPubKey: unittest.MustDecodePublicKeyHex(crypto.ECDSAP256, "697241208dcc9142b6f53064adc8ff1c95760c68beb2ba083c1d005d40181fd7a1b113274e0163c053a3addd47cd528ec6a1f190cf465aac87c415feaae011ae"),
StakingPubKey: unittest.MustDecodePublicKeyHex(crypto.BLSBLS12381, "b1f97d0a06020eca97352e1adde72270ee713c7daf58da7e74bf72235321048b4841bdfc28227964bf18e371e266e32107d238358848bcc5d0977a0db4bda0b4c33d3874ff991e595e0f537c7b87b4ddce92038ebc7b295c9ea20a1492302aa7"),
NetworkPubKey: MustDecodePublicKeyHex(crypto.ECDSAP256, "697241208dcc9142b6f53064adc8ff1c95760c68beb2ba083c1d005d40181fd7a1b113274e0163c053a3addd47cd528ec6a1f190cf465aac87c415feaae011ae"),
StakingPubKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "b1f97d0a06020eca97352e1adde72270ee713c7daf58da7e74bf72235321048b4841bdfc28227964bf18e371e266e32107d238358848bcc5d0977a0db4bda0b4c33d3874ff991e595e0f537c7b87b4ddce92038ebc7b295c9ea20a1492302aa7"),
Weight: 100,
},
},
Expand All @@ -117,7 +116,7 @@ func EpochCommitFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.EpochCom
panic(err)
}

event := unittest.EventFixture(events.EpochCommit.EventType(), 1, 1, unittest.IdentifierFixture(), 0)
event := EventFixture(events.EpochCommit.EventType(), 1, 1, IdentifierFixture(), 0)
event.Payload = []byte(EpochCommitFixtureJSON)

expected := &flow.EpochCommit{
Expand All @@ -128,19 +127,19 @@ func EpochCommitFixtureByChainID(chain flow.ChainID) (flow.Event, *flow.EpochCom
flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000001"),
flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000002"),
},
SigData: unittest.MustDecodeSignatureHex("b072ed22ed305acd44818a6c836e09b4e844eebde6a4fdbf5cec983e2872b86c8b0f6c34c0777bf52e385ab7c45dc55d"),
SigData: MustDecodeSignatureHex("b072ed22ed305acd44818a6c836e09b4e844eebde6a4fdbf5cec983e2872b86c8b0f6c34c0777bf52e385ab7c45dc55d"),
},
{
VoterIDs: []flow.Identifier{
flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000003"),
flow.MustHexStringToIdentifier("0000000000000000000000000000000000000000000000000000000000000004"),
},
SigData: unittest.MustDecodeSignatureHex("899e266a543e1b3a564f68b22f7be571f2e944ec30fadc4b39e2d5f526ba044c0f3cb2648f8334fc216fa3360a0418b2"),
SigData: MustDecodeSignatureHex("899e266a543e1b3a564f68b22f7be571f2e944ec30fadc4b39e2d5f526ba044c0f3cb2648f8334fc216fa3360a0418b2"),
},
},
DKGGroupKey: unittest.MustDecodePublicKeyHex(crypto.BLSBLS12381, "8c588266db5f5cda629e83f8aa04ae9413593fac19e4865d06d291c9d14fbdd9bdb86a7a12f9ef8590c79cb635e3163315d193087e9336092987150d0cd2b14ac6365f7dc93eec573752108b8c12368abb65f0652d9f644e5aed611c37926950"),
DKGGroupKey: MustDecodePublicKeyHex(crypto.BLSBLS12381, "8c588266db5f5cda629e83f8aa04ae9413593fac19e4865d06d291c9d14fbdd9bdb86a7a12f9ef8590c79cb635e3163315d193087e9336092987150d0cd2b14ac6365f7dc93eec573752108b8c12368abb65f0652d9f644e5aed611c37926950"),
DKGParticipantKeys: []crypto.PublicKey{
unittest.MustDecodePublicKeyHex(crypto.BLSBLS12381, "87a339e4e5c74f089da20a33f515d8c8f4464ab53ede5a74aa2432cd1ae66d522da0c122249ee176cd747ddc83ca81090498389384201614caf51eac392c1c0a916dfdcfbbdf7363f9552b6468434add3d3f6dc91a92bbe3ee368b59b7828488"),
MustDecodePublicKeyHex(crypto.BLSBLS12381, "87a339e4e5c74f089da20a33f515d8c8f4464ab53ede5a74aa2432cd1ae66d522da0c122249ee176cd747ddc83ca81090498389384201614caf51eac392c1c0a916dfdcfbbdf7363f9552b6468434add3d3f6dc91a92bbe3ee368b59b7828488"),
},
}

Expand Down

0 comments on commit a525801

Please sign in to comment.