Skip to content

Commit

Permalink
Merge pull request #6594 from bluesign/withoutEmulator
Browse files Browse the repository at this point in the history
Minimal emulator implementation inside integration
  • Loading branch information
jordanschalm authored Oct 25, 2024
2 parents 8d5a3b3 + d6fe283 commit c1a1cc0
Show file tree
Hide file tree
Showing 42 changed files with 10,541 additions and 105 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ go-math-rand-check:
# - "onflow/crypto/random" for deterministic randomness
grep --include=\*.go \
--exclude=*test* --exclude=*helper* --exclude=*example* --exclude=*fixture* --exclude=*benchmark* --exclude=*profiler* \
--exclude-dir=*test* --exclude-dir=*helper* --exclude-dir=*example* --exclude-dir=*fixture* --exclude-dir=*benchmark* --exclude-dir=*profiler* -rnw '"math/rand"'; \
--exclude-dir=*test* --exclude-dir=*helper* --exclude-dir=*example* --exclude-dir=*fixture* --exclude-dir=*benchmark* --exclude-dir=*profiler* --exclude-dir=*emulator* -rnw '"math/rand"'; \
if [ $$? -ne 1 ]; then \
echo "[Error] Go production code should not use math/rand package"; exit 1; \
fi
Expand Down
4 changes: 2 additions & 2 deletions integration/benchmark/load/load_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/onflow/cadence"
"github.com/onflow/cadence/encoding/ccf"
convert2 "github.com/onflow/flow-emulator/convert"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"

Expand All @@ -28,6 +27,7 @@ import (
"github.com/onflow/flow-go/integration/benchmark/common"
"github.com/onflow/flow-go/integration/benchmark/load"
"github.com/onflow/flow-go/integration/convert"
"github.com/onflow/flow-go/integration/internal/emulator"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/utils/unittest"
)
Expand Down Expand Up @@ -254,7 +254,7 @@ func (t *testTransactionSender) Send(tx *sdk.Transaction) (sdk.TransactionResult
Error: result.Err,
BlockID: sdk.EmptyID,
BlockHeight: 0,
TransactionID: convert2.FlowIdentifierToSDK(txBody.ID()),
TransactionID: emulator.FlowIdentifierToSDK(txBody.ID()),
CollectionID: sdk.EmptyID,
}

Expand Down
38 changes: 18 additions & 20 deletions integration/dkg/dkg_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import (
"github.com/stretchr/testify/suite"

"github.com/onflow/cadence"

jsoncdc "github.com/onflow/cadence/encoding/json"
emulator "github.com/onflow/flow-emulator/emulator"

"github.com/onflow/crypto"
"github.com/onflow/flow-core-contracts/lib/go/contracts"
"github.com/onflow/flow-core-contracts/lib/go/templates"
Expand All @@ -23,6 +20,7 @@ import (
sdktemplates "github.com/onflow/flow-go-sdk/templates"
"github.com/onflow/flow-go-sdk/test"

emulator "github.com/onflow/flow-go/integration/internal/emulator"
"github.com/onflow/flow-go/integration/utils"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/dkg"
Expand All @@ -34,13 +32,13 @@ type ClientSuite struct {

contractClient *dkg.Client

env templates.Environment
blockchain emulator.Emulator
emulatorClient *utils.EmulatorClient

dkgAddress sdk.Address
dkgAccountKey *sdk.AccountKey
dkgSigner sdkcrypto.Signer
env templates.Environment
blockchain emulator.Emulator
emulatorClient *utils.EmulatorClient
serviceAccountAddress sdk.Address
dkgAddress sdk.Address
dkgAccountKey *sdk.AccountKey
dkgSigner sdkcrypto.Signer
}

func TestDKGClient(t *testing.T) {
Expand All @@ -57,7 +55,7 @@ func (s *ClientSuite) SetupTest() {

s.blockchain = blockchain
s.emulatorClient = utils.NewEmulatorClient(blockchain)

s.serviceAccountAddress = sdk.Address(s.blockchain.ServiceKey().Address)
// deploy contract
s.deployDKGContract()

Expand Down Expand Up @@ -234,16 +232,16 @@ func (s *ClientSuite) setUpAdmin() {
setUpAdminTx := sdk.NewTransaction().
SetScript(templates.GeneratePublishDKGParticipantScript(s.env)).
SetComputeLimit(9999).
SetProposalKey(s.blockchain.ServiceKey().Address, s.blockchain.ServiceKey().Index,
SetProposalKey(s.serviceAccountAddress, s.blockchain.ServiceKey().Index,
s.blockchain.ServiceKey().SequenceNumber).
SetPayer(s.blockchain.ServiceKey().Address).
SetPayer(s.serviceAccountAddress).
AddAuthorizer(s.dkgAddress)

signer, err := s.blockchain.ServiceKey().Signer()
require.NoError(s.T(), err)

s.signAndSubmit(setUpAdminTx,
[]sdk.Address{s.blockchain.ServiceKey().Address, s.dkgAddress},
[]sdk.Address{s.serviceAccountAddress, s.dkgAddress},
[]sdkcrypto.Signer{signer, s.dkgSigner},
)
}
Expand All @@ -262,9 +260,9 @@ func (s *ClientSuite) startDKGWithParticipants(nodeIDs []flow.Identifier) {
startDKGTx := sdk.NewTransaction().
SetScript(templates.GenerateStartDKGScript(s.env)).
SetComputeLimit(9999).
SetProposalKey(s.blockchain.ServiceKey().Address, s.blockchain.ServiceKey().Index,
SetProposalKey(s.serviceAccountAddress, s.blockchain.ServiceKey().Index,
s.blockchain.ServiceKey().SequenceNumber).
SetPayer(s.blockchain.ServiceKey().Address).
SetPayer(s.serviceAccountAddress).
AddAuthorizer(s.dkgAddress)

err := startDKGTx.AddArgument(cadence.NewArray(valueNodeIDs))
Expand All @@ -274,7 +272,7 @@ func (s *ClientSuite) startDKGWithParticipants(nodeIDs []flow.Identifier) {
require.NoError(s.T(), err)

s.signAndSubmit(startDKGTx,
[]sdk.Address{s.blockchain.ServiceKey().Address, s.dkgAddress},
[]sdk.Address{s.serviceAccountAddress, s.dkgAddress},
[]sdkcrypto.Signer{signer, s.dkgSigner},
)

Expand All @@ -293,9 +291,9 @@ func (s *ClientSuite) createParticipant(nodeID flow.Identifier, authoriser sdk.A
createParticipantTx := sdk.NewTransaction().
SetScript(templates.GenerateCreateDKGParticipantScript(s.env)).
SetComputeLimit(9999).
SetProposalKey(s.blockchain.ServiceKey().Address, s.blockchain.ServiceKey().Index,
SetProposalKey(s.serviceAccountAddress, s.blockchain.ServiceKey().Index,
s.blockchain.ServiceKey().SequenceNumber).
SetPayer(s.blockchain.ServiceKey().Address).
SetPayer(s.serviceAccountAddress).
AddAuthorizer(authoriser)

err := createParticipantTx.AddArgument(cadence.NewAddress(s.dkgAddress))
Expand All @@ -310,7 +308,7 @@ func (s *ClientSuite) createParticipant(nodeID flow.Identifier, authoriser sdk.A
require.NoError(s.T(), err)

s.signAndSubmit(createParticipantTx,
[]sdk.Address{s.blockchain.ServiceKey().Address, authoriser},
[]sdk.Address{s.serviceAccountAddress, authoriser},
[]sdkcrypto.Signer{s2, signer},
)

Expand Down
47 changes: 23 additions & 24 deletions integration/dkg/dkg_emulator_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@ import (
jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/onflow/flow-core-contracts/lib/go/contracts"
"github.com/onflow/flow-core-contracts/lib/go/templates"
emulator "github.com/onflow/flow-emulator/emulator"

sdk "github.com/onflow/flow-go-sdk"
sdkcrypto "github.com/onflow/flow-go-sdk/crypto"
sdktemplates "github.com/onflow/flow-go-sdk/templates"
"github.com/onflow/flow-go-sdk/test"

"github.com/onflow/flow-go/module/metrics"

dkgeng "github.com/onflow/flow-go/engine/consensus/dkg"
"github.com/onflow/flow-go/engine/testutil"
"github.com/onflow/flow-go/fvm/systemcontracts"
emulator "github.com/onflow/flow-go/integration/internal/emulator"
"github.com/onflow/flow-go/integration/tests/lib"
"github.com/onflow/flow-go/integration/utils"
"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/module/dkg"
"github.com/onflow/flow-go/module/metrics"
"github.com/onflow/flow-go/network/stub"
"github.com/onflow/flow-go/state/protocol/events/gadgets"
"github.com/onflow/flow-go/storage/badger"
Expand All @@ -54,10 +53,10 @@ type EmulatorSuite struct {
dkgAccountKey *sdk.AccountKey
dkgSigner sdkcrypto.Signer
checkDKGUnhappy bool // activate log hook for DKGBroker to check if the DKG core is flagging misbehaviours

netIDs flow.IdentityList
nodeAccounts []*nodeAccount
nodes []*node
serviceAccountAddress sdk.Address
netIDs flow.IdentityList
nodeAccounts []*nodeAccount
nodes []*node
}

func (s *EmulatorSuite) SetupTest() {
Expand Down Expand Up @@ -119,7 +118,7 @@ func (s *EmulatorSuite) initEmulator() {
s.Require().NoError(err)

s.blockchain = blockchain

s.serviceAccountAddress = sdk.Address(s.blockchain.ServiceKey().Address)
s.adminEmulatorClient = utils.NewEmulatorClient(blockchain)

s.hub = stub.NewNetworkHub()
Expand Down Expand Up @@ -163,15 +162,15 @@ func (s *EmulatorSuite) setupDKGAdmin() {
SetScript(templates.GeneratePublishDKGParticipantScript(s.env)).
SetComputeLimit(9999).
SetProposalKey(
s.blockchain.ServiceKey().Address,
s.serviceAccountAddress,
s.blockchain.ServiceKey().Index,
s.blockchain.ServiceKey().SequenceNumber).
SetPayer(s.blockchain.ServiceKey().Address).
SetPayer(s.serviceAccountAddress).
AddAuthorizer(s.dkgAddress)
signer, err := s.blockchain.ServiceKey().Signer()
require.NoError(s.T(), err)
_, err = s.prepareAndSubmit(setUpAdminTx,
[]sdk.Address{s.blockchain.ServiceKey().Address, s.dkgAddress},
[]sdk.Address{s.serviceAccountAddress, s.dkgAddress},
[]sdkcrypto.Signer{signer, s.dkgSigner},
)
require.NoError(s.T(), err)
Expand Down Expand Up @@ -229,13 +228,13 @@ func (s *EmulatorSuite) createAndFundAccount(netID bootstrap.NodeInfo) *nodeAcco
sc.FungibleToken.Address.Hex(),
sc.FlowToken.Address.Hex(),
))).
AddAuthorizer(s.blockchain.ServiceKey().Address).
AddAuthorizer(s.serviceAccountAddress).
SetProposalKey(
s.blockchain.ServiceKey().Address,
s.serviceAccountAddress,
s.blockchain.ServiceKey().Index,
s.blockchain.ServiceKey().SequenceNumber,
).
SetPayer(s.blockchain.ServiceKey().Address)
SetPayer(s.serviceAccountAddress)

err = fundAccountTx.AddArgument(cadence.UFix64(1_000_000))
require.NoError(s.T(), err)
Expand All @@ -244,7 +243,7 @@ func (s *EmulatorSuite) createAndFundAccount(netID bootstrap.NodeInfo) *nodeAcco
signer, err := s.blockchain.ServiceKey().Signer()
require.NoError(s.T(), err)
_, err = s.prepareAndSubmit(fundAccountTx,
[]sdk.Address{s.blockchain.ServiceKey().Address},
[]sdk.Address{s.serviceAccountAddress},
[]sdkcrypto.Signer{signer},
)
require.NoError(s.T(), err)
Expand Down Expand Up @@ -307,18 +306,18 @@ func (s *EmulatorSuite) startDKGWithParticipants(accounts []*nodeAccount) {
SetScript(templates.GenerateStartDKGScript(s.env)).
SetComputeLimit(9999).
SetProposalKey(
s.blockchain.ServiceKey().Address,
s.serviceAccountAddress,
s.blockchain.ServiceKey().Index,
s.blockchain.ServiceKey().SequenceNumber).
SetPayer(s.blockchain.ServiceKey().Address).
SetPayer(s.serviceAccountAddress).
AddAuthorizer(s.dkgAddress)

err := startDKGTx.AddArgument(cadence.NewArray(valueNodeIDs))
require.NoError(s.T(), err)
signer, err := s.blockchain.ServiceKey().Signer()
require.NoError(s.T(), err)
_, err = s.prepareAndSubmit(startDKGTx,
[]sdk.Address{s.blockchain.ServiceKey().Address, s.dkgAddress},
[]sdk.Address{s.serviceAccountAddress, s.dkgAddress},
[]sdkcrypto.Signer{signer, s.dkgSigner},
)
require.NoError(s.T(), err)
Expand All @@ -334,7 +333,7 @@ func (s *EmulatorSuite) claimDKGParticipant(node *node) {
SetScript(templates.GenerateCreateDKGParticipantScript(s.env)).
SetComputeLimit(9999).
SetProposalKey(
s.blockchain.ServiceKey().Address,
s.serviceAccountAddress,
s.blockchain.ServiceKey().Index,
s.blockchain.ServiceKey().SequenceNumber,
).
Expand All @@ -350,7 +349,7 @@ func (s *EmulatorSuite) claimDKGParticipant(node *node) {
signer, err := s.blockchain.ServiceKey().Signer()
require.NoError(s.T(), err)
_, err = s.prepareAndSubmit(createParticipantTx,
[]sdk.Address{node.account.accountAddress, s.blockchain.ServiceKey().Address, s.dkgAddress},
[]sdk.Address{node.account.accountAddress, s.serviceAccountAddress, s.dkgAddress},
[]sdkcrypto.Signer{node.account.accountSigner, signer, s.dkgSigner},
)
require.NoError(s.T(), err)
Expand All @@ -371,21 +370,21 @@ func (s *EmulatorSuite) sendDummyTx() (*flow.Block, error) {
createAccountTx, err := sdktemplates.CreateAccount(
[]*sdk.AccountKey{test.AccountKeyGenerator().New()},
[]sdktemplates.Contract{},
s.blockchain.ServiceKey().Address)
s.serviceAccountAddress)
if err != nil {
return nil, err
}
createAccountTx.
SetProposalKey(
s.blockchain.ServiceKey().Address,
s.serviceAccountAddress,
s.blockchain.ServiceKey().Index,
s.blockchain.ServiceKey().SequenceNumber).
SetPayer(s.blockchain.ServiceKey().Address)
SetPayer(s.serviceAccountAddress)

signer, err := s.blockchain.ServiceKey().Signer()
require.NoError(s.T(), err)
block, err := s.prepareAndSubmit(createAccountTx,
[]sdk.Address{s.blockchain.ServiceKey().Address},
[]sdk.Address{s.serviceAccountAddress},
[]sdkcrypto.Signer{signer},
)
return block, err
Expand Down
Loading

0 comments on commit c1a1cc0

Please sign in to comment.