MCPcopy Create free account
hub / github.com/CPChain/chain / TestReorgSideEvent

Function TestReorgSideEvent

core/blockchain_test.go:624–708  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

622}
623
624func TestReorgSideEvent(t *testing.T) {
625 t.Skip("=== Diff TestReorgSideEvent")
626 // NB the signer is changed to cip1
627 var (
628 db = database.NewMemDatabase()
629 remoteDB = database.NewIpfsDbWithAdapter(database.NewFakeIpfsAdapter())
630 key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
631 addr1 = crypto.PubkeyToAddress(key1.PublicKey)
632 gspec = &Genesis{
633 Config: configs.TestChainConfig,
634 Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000)}},
635 }
636 genesis = gspec.MustCommit(db)
637 signer = types.NewCep1Signer(gspec.Config.ChainID)
638 )
639
640 blockchain, _ := NewBlockChain(db, nil, gspec.Config, fakeDpor(db), vm.Config{}, nil, nil)
641 defer blockchain.Stop()
642
643 chain, _ := GenerateChain(gspec.Config, genesis, fakeDpor(db), db, remoteDB, 3, func(i int, gen *BlockGen) {})
644 if _, err := blockchain.InsertChain(chain); err != nil {
645 t.Fatalf("failed to insert chain: %v", err)
646 }
647
648 replacementBlocks, _ := GenerateChain(gspec.Config, genesis, fakeDpor(db), db, remoteDB, 4, func(i int, gen *BlockGen) {
649 tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), 1000000, new(big.Int), nil), signer, key1)
650 if i == 2 {
651 gen.OffsetTime(-9)
652 }
653 if err != nil {
654 t.Fatalf("failed to create tx: %v", err)
655 }
656 gen.AddTx(tx)
657 })
658 chainSideCh := make(chan ChainSideEvent, 64)
659 blockchain.SubscribeChainSideEvent(chainSideCh)
660 if _, err := blockchain.InsertChain(replacementBlocks); err != nil {
661 t.Fatalf("failed to insert chain: %v", err)
662 }
663
664 // first two block of the secondary chain are for a brief moment considered
665 // side chains because up to that point the first one is considered the
666 // heavier chain.
667 expectedSideHashes := map[common.Hash]bool{
668 replacementBlocks[0].Hash(): true,
669 replacementBlocks[1].Hash(): true,
670 chain[0].Hash(): true,
671 chain[1].Hash(): true,
672 chain[2].Hash(): true,
673 }
674
675 i := 0
676
677 const timeoutDura = 10 * time.Second
678 timeout := time.NewTimer(timeoutDura)
679done:
680 for {
681 select {

Callers

nothing calls this directly

Calls 15

StopMethod · 0.95
InsertChainMethod · 0.95
NewBlockChainFunction · 0.85
fakeDporFunction · 0.85
GenerateChainFunction · 0.85
MustCommitMethod · 0.80
TxNonceMethod · 0.80
OffsetTimeMethod · 0.80
AddTxMethod · 0.80
SignTxMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected