MCPcopy Create free account
hub / github.com/chain/txvm / newTestChain

Function newTestChain

protocol/block_test.go:280–305  ·  view source on GitHub ↗

newTestChain returns a new Chain using memstore for storage, along with an initial block b1 (with a 0/0 multisig program). It commits b1 before returning.

(tb testing.TB, ts time.Time)

Source from the content-addressed store, hash-verified

278// along with an initial block b1 (with a 0/0 multisig program).
279// It commits b1 before returning.
280func newTestChain(tb testing.TB, ts time.Time) (c *Chain, sb1 *bc.Block) {
281 ctx := context.Background()
282
283 var err error
284
285 b1, err := NewInitialBlock(nil, 0, ts)
286 if err != nil {
287 testutil.FatalErr(tb, err)
288 }
289 c, err = NewChain(ctx, b1, memstore.New(), nil)
290 if err != nil {
291 testutil.FatalErr(tb, err)
292 }
293 c.bb.MaxNonceWindow = 48 * time.Hour
294 c.bb.MaxBlockWindow = 100
295 st := state.Empty()
296 err = st.ApplyBlock(b1.UnsignedBlock)
297 if err != nil {
298 testutil.FatalErr(tb, err)
299 }
300 err = c.CommitAppliedBlock(ctx, b1, st)
301 if err != nil {
302 testutil.FatalErr(tb, err)
303 }
304 return c, b1
305}
306
307func mustDecodeHash(s string) (h bc.Hash) {
308 err := h.UnmarshalText([]byte(s))

Callers 4

TestGenerateBlockFunction · 0.85
TestPersistSnapshotFunction · 0.85
TestBadMaxNonceWindowFunction · 0.85

Calls 7

FatalErrFunction · 0.92
NewFunction · 0.92
EmptyFunction · 0.92
NewInitialBlockFunction · 0.85
ApplyBlockMethod · 0.80
CommitAppliedBlockMethod · 0.80
NewChainFunction · 0.70

Tested by

no test coverage detected