From 1f59eee7d83120def0f122e6ac529b8065ff1593 Mon Sep 17 00:00:00 2001 From: frrist Date: Thu, 6 Jun 2019 09:13:11 -0700 Subject: [PATCH] rename DefaultGenesis to TestGenesis - moved to testing as its only used in testing --- actor/builtin/miner_redeem_test.go | 2 +- actor/builtin/paymentbroker/paymentbroker_test.go | 2 +- consensus/expected_test.go | 2 +- consensus/genesis.go | 5 ----- consensus/testing.go | 13 ++++++++++--- core/testing.go | 2 +- node/node_test.go | 8 ++++---- node/testing.go | 4 ++-- plumbing/msg/waiter_test.go | 2 +- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/actor/builtin/miner_redeem_test.go b/actor/builtin/miner_redeem_test.go index 309b947c2e..c683f6254f 100644 --- a/actor/builtin/miner_redeem_test.go +++ b/actor/builtin/miner_redeem_test.go @@ -190,7 +190,7 @@ func requireGenesis(ctx context.Context, t *testing.T, targetAddresses ...addres vms := vm.NewStorageMap(bs) cst := hamt.NewCborStore() - blk, err := consensus.DefaultGenesis(cst, bs) + blk, err := consensus.TestGenesis(cst, bs) require.NoError(err) st, err := state.LoadStateTree(ctx, cst, blk.StateRoot, builtin.Actors) diff --git a/actor/builtin/paymentbroker/paymentbroker_test.go b/actor/builtin/paymentbroker/paymentbroker_test.go index fc69940ccf..2db0dea15c 100644 --- a/actor/builtin/paymentbroker/paymentbroker_test.go +++ b/actor/builtin/paymentbroker/paymentbroker_test.go @@ -1124,7 +1124,7 @@ func requireGenesis(ctx context.Context, t *testing.T, targetAddresses ...addres vms := vm.NewStorageMap(bs) cst := hamt.NewCborStore() - blk, err := consensus.DefaultGenesis(cst, bs) + blk, err := consensus.TestGenesis(cst, bs) require.NoError(t, err) builtinsWithTestActor := map[cid.Cid]exec.ExecutableActor{} diff --git a/consensus/expected_test.go b/consensus/expected_test.go index 0654867884..d2b9b5ccf8 100644 --- a/consensus/expected_test.go +++ b/consensus/expected_test.go @@ -84,7 +84,7 @@ func TestExpected_RunStateTransition_validateMining(t *testing.T) { ctx := context.Background() cistore, bstore, verifier := setupCborBlockstoreProofs() - genesisBlock, err := consensus.DefaultGenesis(cistore, bstore) + genesisBlock, err := consensus.TestGenesis(cistore, bstore) require.NoError(t, err) t.Run("passes the validateMining section when given valid mining blocks", func(t *testing.T) { diff --git a/consensus/genesis.go b/consensus/genesis.go index 33ed4e55d7..0bc681df26 100644 --- a/consensus/genesis.go +++ b/consensus/genesis.go @@ -192,11 +192,6 @@ func MakeGenesisFunc(opts ...GenOption) GenesisInitFunc { } } -// DefaultGenesis creates a genesis block with default accounts and actors installed. -func DefaultGenesis(cst *hamt.CborIpldStore, bs blockstore.Blockstore) (*types.Block, error) { - return MakeGenesisFunc()(cst, bs) -} - // SetupDefaultActors inits the builtin actors that are required to run filecoin. func SetupDefaultActors(ctx context.Context, st state.Tree, storageMap vm.StorageMap, storeType types.ProofsMode) error { for addr, val := range defaultAccounts { diff --git a/consensus/testing.go b/consensus/testing.go index 9f60c81725..1dcc39ff3a 100644 --- a/consensus/testing.go +++ b/consensus/testing.go @@ -2,15 +2,22 @@ package consensus import ( "context" + + "github.com/ipfs/go-hamt-ipld" + "github.com/ipfs/go-ipfs-blockstore" + "github.com/stretchr/testify/require" + "github.com/filecoin-project/go-filecoin/actor" "github.com/filecoin-project/go-filecoin/address" "github.com/filecoin-project/go-filecoin/state" "github.com/filecoin-project/go-filecoin/types" - "github.com/ipfs/go-ipfs-blockstore" - - "github.com/stretchr/testify/require" ) +// TestGenesis creates a genesis block with default accounts and actors installed for testing. +func TestGenesis(cst *hamt.CborIpldStore, bs blockstore.Blockstore) (*types.Block, error) { + return MakeGenesisFunc()(cst, bs) +} + // TestView is an implementation of stateView used for testing the chain // manager. It provides a consistent view that the storage market // that returns 1 for storage total and 1 for any miner storage. diff --git a/core/testing.go b/core/testing.go index 1b0a3a0879..f32b9607af 100644 --- a/core/testing.go +++ b/core/testing.go @@ -137,7 +137,7 @@ func CreateStorages(ctx context.Context, t *testing.T) (state.Tree, vm.StorageMa cst := hamt.NewCborStore() d := datastore.NewMapDatastore() bs := blockstore.NewBlockstore(d) - blk, err := consensus.DefaultGenesis(cst, bs) + blk, err := consensus.TestGenesis(cst, bs) require.NoError(t, err) st, err := state.LoadStateTree(ctx, cst, blk.StateRoot, builtin.Actors) diff --git a/node/node_test.go b/node/node_test.go index 5aa08a2ad0..5f58267a81 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -60,7 +60,7 @@ func TestConnectsToBootstrapNodes(t *testing.T) { r := repo.NewInMemoryRepo() r.Config().Swarm.Address = "/ip4/0.0.0.0/tcp/0" - require.NoError(t, node.Init(ctx, r, consensus.DefaultGenesis)) + require.NoError(t, node.Init(ctx, r, consensus.TestGenesis)) r.Config().Bootstrap.Addresses = []string{} opts, err := node.OptionsFromRepo(r) require.NoError(t, err) @@ -87,7 +87,7 @@ func TestConnectsToBootstrapNodes(t *testing.T) { r := repo.NewInMemoryRepo() r.Config().Swarm.Address = "/ip4/0.0.0.0/tcp/0" - require.NoError(t, node.Init(ctx, r, consensus.DefaultGenesis)) + require.NoError(t, node.Init(ctx, r, consensus.TestGenesis)) r.Config().Bootstrap.Addresses = []string{peer1, peer2} opts, err := node.OptionsFromRepo(r) @@ -169,7 +169,7 @@ func TestOptionWithError(t *testing.T) { ctx := context.Background() r := repo.NewInMemoryRepo() - assert.NoError(t, node.Init(ctx, r, consensus.DefaultGenesis)) + assert.NoError(t, node.Init(ctx, r, consensus.TestGenesis)) opts, err := node.OptionsFromRepo(r) assert.NoError(t, err) @@ -208,7 +208,7 @@ func TestNodeConfig(t *testing.T) { ConfigOpts: configOptions, InitOpts: initOpts, OfflineMode: true, - GenesisFunc: consensus.DefaultGenesis, + GenesisFunc: consensus.TestGenesis, } n := node.GenNode(t, &tno) diff --git a/node/testing.go b/node/testing.go index 95b66a505e..0f4632e6a0 100644 --- a/node/testing.go +++ b/node/testing.go @@ -177,7 +177,7 @@ func MakeNodesUnstartedWithGif(t *testing.T, numNodes int, offlineMode bool, gif // MakeNodesUnstarted creates some new nodes with an InMemoryRepo, fake proof verifier, and default genesis block. // Call StartNodes to start them. func MakeNodesUnstarted(t *testing.T, numNodes int, offlineMode bool) []*Node { - return MakeNodesUnstartedWithGif(t, numNodes, offlineMode, consensus.DefaultGenesis) + return MakeNodesUnstartedWithGif(t, numNodes, offlineMode, consensus.TestGenesis) } // MakeOfflineNode returns a single unstarted offline node. @@ -185,7 +185,7 @@ func MakeOfflineNode(t *testing.T) *Node { return MakeNodesUnstartedWithGif(t, 1, /* 1 node */ true, /* offline */ - consensus.DefaultGenesis)[0] + consensus.TestGenesis)[0] } // DefaultTestingConfig returns default configuration for testing diff --git a/plumbing/msg/waiter_test.go b/plumbing/msg/waiter_test.go index 115f45e5c4..ae255a9063 100644 --- a/plumbing/msg/waiter_test.go +++ b/plumbing/msg/waiter_test.go @@ -45,7 +45,7 @@ type smsgs []*types.SignedMessage type smsgsSet [][]*types.SignedMessage func setupTest(t *testing.T) (*hamt.CborIpldStore, *chain.Store, *Waiter) { - d := requiredCommonDeps(t, consensus.DefaultGenesis) + d := requiredCommonDeps(t, consensus.TestGenesis) return d.cst, d.chainStore, NewWaiter(d.chainStore, d.blockstore, d.cst) }