diff options
-rw-r--r-- | core/blockchain_test.go | 78 | ||||
-rw-r--r-- | internal/build/env.go | 7 |
2 files changed, 77 insertions, 8 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 = ¶ms.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 = ¶ms.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 = ¶ms.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") + } +} diff --git a/internal/build/env.go b/internal/build/env.go index 95281df86..15b2dfe41 100644 --- a/internal/build/env.go +++ b/internal/build/env.go @@ -20,6 +20,7 @@ import ( "flag" "fmt" "os" + "strings" ) var ( @@ -89,11 +90,15 @@ func LocalEnv() Environment { } } if env.Tag == "" { - env.Tag = RunGit("for-each-ref", "--points-at=HEAD", "--count=1", "--format=%(refname:short)", "refs/tags") + env.Tag = firstLine(RunGit("tag", "-l", "--points-at", "HEAD")) } return env } +func firstLine(s string) string { + return strings.Split(s, "\n")[0] +} + func applyEnvFlags(env Environment) Environment { if !flag.Parsed() { panic("you need to call flag.Parse before Env or LocalEnv") |