aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain_test.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-12-01 07:11:24 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-12-01 19:12:30 +0800
commit9901a40f047f55d1a756805bdeed3997d071c3d1 (patch)
tree07f07607ab2647f200b2ac17d0cbc3136e68a03f /core/blockchain_test.go
parent7dde2b902cf81e90b484b1a48f6d45e0abd10e0f (diff)
downloadgo-tangerine-9901a40f047f55d1a756805bdeed3997d071c3d1.tar.gz
go-tangerine-9901a40f047f55d1a756805bdeed3997d071c3d1.tar.zst
go-tangerine-9901a40f047f55d1a756805bdeed3997d071c3d1.zip
core: added a new RemovedLogEvent
When a chain reorganisation occurs we collect the logs that were deleted during the chain reorganisation. The removed logs are posted to the event mux indicating that those were deleted during the reorg.
Diffstat (limited to 'core/blockchain_test.go')
-rw-r--r--core/blockchain_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index 6e1c5fdc7..b4ac1696a 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.go
@@ -963,3 +963,46 @@ func TestChainTxReorgs(t *testing.T) {
}
}
}
+
+func TestLogReorgs(t *testing.T) {
+ params.MinGasLimit = big.NewInt(125000) // Minimum the gas limit may ever be.
+ params.GenesisGasLimit = big.NewInt(3141592) // Gas limit of the Genesis block.
+
+ var (
+ key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
+ addr1 = crypto.PubkeyToAddress(key1.PublicKey)
+ db, _ = ethdb.NewMemDatabase()
+ // this code generates a log
+ code = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00")
+ )
+ genesis := WriteGenesisBlockForTesting(db,
+ GenesisAccount{addr1, big.NewInt(10000000000000)},
+ )
+
+ evmux := &event.TypeMux{}
+ blockchain, _ := NewBlockChain(db, FakePow{}, evmux)
+
+ subs := evmux.Subscribe(RemovedLogEvent{})
+ chain, _ := GenerateChain(genesis, db, 2, func(i int, gen *BlockGen) {
+ if i == 1 {
+ tx, err := types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), big.NewInt(1000000), new(big.Int), code).SignECDSA(key1)
+ if err != nil {
+ t.Fatalf("failed to create tx: %v", err)
+ }
+ gen.AddTx(tx)
+ }
+ })
+ if _, err := blockchain.InsertChain(chain); err != nil {
+ t.Fatalf("failed to insert chain: %v", err)
+ }
+
+ chain, _ = GenerateChain(genesis, db, 3, func(i int, gen *BlockGen) {})
+ if _, err := blockchain.InsertChain(chain); err != nil {
+ t.Fatalf("failed to insert forked chain: %v", err)
+ }
+
+ ev := <-subs.Chan()
+ if len(ev.Data.(RemovedLogEvent).Logs) == 0 {
+ t.Error("expected logs")
+ }
+}