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)
| 278 | // along with an initial block b1 (with a 0/0 multisig program). |
| 279 | // It commits b1 before returning. |
| 280 | func 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 | |
| 307 | func mustDecodeHash(s string) (h bc.Hash) { |
| 308 | err := h.UnmarshalText([]byte(s)) |
no test coverage detected