"github.com/bytom/errors"
"github.com/bytom/log"
- "github.com/bytom/protocol/bc"
"github.com/bytom/protocol/bc/legacy"
"github.com/bytom/protocol/state"
"github.com/bytom/protocol/validation"
c.state.height = h
c.state.cond.Broadcast()
}
-
-func NewInitialBlock(timestamp time.Time) (*legacy.Block, error) {
- // TODO(kr): move this into a lower-level package (e.g. chain/protocol/bc)
- // so that other packages (e.g. chain/protocol/validation) unit tests can
- // call this function.
- root, err := bc.MerkleRoot(nil) // calculate the zero value of the tx merkle root
- if err != nil {
- return nil, errors.Wrap(err, "calculating zero value of tx merkle root")
- }
-
- b := &legacy.Block{
- BlockHeader: legacy.BlockHeader{
- Version: 1,
- Height: 1,
- TimestampMS: bc.Millis(timestamp),
- BlockCommitment: legacy.BlockCommitment{
- TransactionsMerkleRoot: root,
- },
- },
- Transactions: []*legacy.Tx{},
- }
- return b, nil
-}
package prottest
import (
- "context"
"sync"
"testing"
- "time"
"github.com/bytom/crypto/ed25519"
"github.com/bytom/protocol"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/bc/legacy"
- "github.com/bytom/protocol/prottest/memstore"
"github.com/bytom/protocol/state"
"github.com/bytom/testutil"
)
quorum int
}
-// NewChain makes a new Chain. By default it uses a memstore for
-// storage and creates an initial block using a 0/0 multisig program.
-// It commits the initial block before returning the Chain.
-//
-// Its defaults may be overridden by providing Options.
-func NewChain(tb testing.TB, opts ...Option) *protocol.Chain {
- conf := config{store: memstore.New(), initialState: state.Empty()}
- for _, opt := range opts {
- opt(tb, &conf)
- }
-
- ctx := context.Background()
- b1, err := protocol.NewInitialBlock(time.Now())
- if err != nil {
- testutil.FatalErr(tb, err)
- }
- c, err := protocol.NewChain(ctx, b1.Hash(), conf.store, nil)
- if err != nil {
- testutil.FatalErr(tb, err)
- }
- c.MaxIssuanceWindow = 48 * time.Hour // TODO(tessr): consider adding MaxIssuanceWindow to NewChain
-
- err = c.CommitAppliedBlock(ctx, b1, conf.initialState)
- if err != nil {
- testutil.FatalErr(tb, err)
- }
-
- // save block-signing keys in global state
- mutex.Lock()
- blockPubkeys[c] = conf.pubkeys
- blockPrivkeys[c] = conf.privkeys
- mutex.Unlock()
-
- return c
-}
-
// Initial returns the provided Chain's initial block.
func Initial(tb testing.TB, c *protocol.Chain) *legacy.Block {
b1, err := c.GetBlock(1)