aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-11-28 08:33:28 +0800
committerFelix Lange <fjl@twurst.com>2016-11-28 08:33:28 +0800
commit6061707371929bd51c211fbb4ab2b4c223f65544 (patch)
treee443e9b72d9cb730934b43b12bb213867c1ee696 /core
parent4c8c5e2f7410d850ee6068b46c8b880f733743d4 (diff)
downloaddexon-6061707371929bd51c211fbb4ab2b4c223f65544.tar
dexon-6061707371929bd51c211fbb4ab2b4c223f65544.tar.gz
dexon-6061707371929bd51c211fbb4ab2b4c223f65544.tar.bz2
dexon-6061707371929bd51c211fbb4ab2b4c223f65544.tar.lz
dexon-6061707371929bd51c211fbb4ab2b4c223f65544.tar.xz
dexon-6061707371929bd51c211fbb4ab2b4c223f65544.tar.zst
dexon-6061707371929bd51c211fbb4ab2b4c223f65544.zip
core: eip unit tests (#3309)
Diffstat (limited to 'core')
-rw-r--r--core/blockchain_test.go78
1 files changed, 71 insertions, 7 deletions
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index 2d4e2b6b2..62d85e2e5 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.go
@@ -1136,13 +1136,14 @@ func TestCanonicalBlockRetrieval(t *testing.T) {
func TestEIP155Transition(t *testing.T) {
// Configure and generate a sample block chain
var (
- db, _ = ethdb.NewMemDatabase()
- key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
- address = crypto.PubkeyToAddress(key.PublicKey)
- funds = big.NewInt(1000000000)
- genesis = WriteGenesisBlockForTesting(db, GenesisAccount{address, funds})
- config = &params.ChainConfig{ChainId: big.NewInt(1), EIP155Block: big.NewInt(2), HomesteadBlock: new(big.Int)}
- mux event.TypeMux
+ db, _ = ethdb.NewMemDatabase()
+ key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
+ address = crypto.PubkeyToAddress(key.PublicKey)
+ funds = big.NewInt(1000000000)
+ deleteAddr = common.Address{1}
+ genesis = WriteGenesisBlockForTesting(db, GenesisAccount{address, funds}, GenesisAccount{deleteAddr, new(big.Int)})
+ config = &params.ChainConfig{ChainId: big.NewInt(1), EIP155Block: big.NewInt(2), HomesteadBlock: new(big.Int)}
+ mux event.TypeMux
)
blockchain, _ := NewBlockChain(db, config, FakePow{}, &mux)
@@ -1231,3 +1232,66 @@ func TestEIP155Transition(t *testing.T) {
t.Error("expected error:", types.ErrInvalidChainId)
}
}
+
+func TestEIP161AccountRemoval(t *testing.T) {
+ // Configure and generate a sample block chain
+ var (
+ db, _ = ethdb.NewMemDatabase()
+ key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
+ address = crypto.PubkeyToAddress(key.PublicKey)
+ funds = big.NewInt(1000000000)
+ theAddr = common.Address{1}
+ genesis = WriteGenesisBlockForTesting(db, GenesisAccount{address, funds})
+ config = &params.ChainConfig{
+ ChainId: big.NewInt(1),
+ HomesteadBlock: new(big.Int),
+ EIP155Block: new(big.Int),
+ EIP158Block: big.NewInt(2),
+ }
+ mux event.TypeMux
+
+ blockchain, _ = NewBlockChain(db, config, FakePow{}, &mux)
+ )
+ blocks, _ := GenerateChain(config, genesis, db, 3, func(i int, block *BlockGen) {
+ var (
+ tx *types.Transaction
+ err error
+ signer = types.NewEIP155Signer(config.ChainId)
+ )
+ switch i {
+ case 0:
+ tx, err = types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), big.NewInt(21000), new(big.Int), nil).SignECDSA(signer, key)
+ case 1:
+ tx, err = types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), big.NewInt(21000), new(big.Int), nil).SignECDSA(signer, key)
+ case 2:
+ tx, err = types.NewTransaction(block.TxNonce(address), theAddr, new(big.Int), big.NewInt(21000), new(big.Int), nil).SignECDSA(signer, key)
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ block.AddTx(tx)
+ })
+ // account must exist pre eip 161
+ if _, err := blockchain.InsertChain(types.Blocks{blocks[0]}); err != nil {
+ t.Fatal(err)
+ }
+ if !blockchain.stateCache.Exist(theAddr) {
+ t.Error("expected account to exist")
+ }
+
+ // account needs to be deleted post eip 161
+ if _, err := blockchain.InsertChain(types.Blocks{blocks[1]}); err != nil {
+ t.Fatal(err)
+ }
+ if blockchain.stateCache.Exist(theAddr) {
+ t.Error("account should not expect")
+ }
+
+ // account musn't be created post eip 161
+ if _, err := blockchain.InsertChain(types.Blocks{blocks[2]}); err != nil {
+ t.Fatal(err)
+ }
+ if blockchain.stateCache.Exist(theAddr) {
+ t.Error("account should not expect")
+ }
+}