aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-23 23:47:05 +0800
committerobscuren <geffobscura@gmail.com>2015-03-23 23:47:05 +0800
commit211cb03f83c8bdfd29af31fd27dc531dfcb13630 (patch)
tree7c1296a6194db41a8d8b25a89dd7aa442d6b4fe5 /tests
parent253ecdc8bba1b522e80fdee69410854f19a5a972 (diff)
parent9562a9840f783e6252ebc6fb8da62b81004f62e8 (diff)
downloaddexon-211cb03f83c8bdfd29af31fd27dc531dfcb13630.tar
dexon-211cb03f83c8bdfd29af31fd27dc531dfcb13630.tar.gz
dexon-211cb03f83c8bdfd29af31fd27dc531dfcb13630.tar.bz2
dexon-211cb03f83c8bdfd29af31fd27dc531dfcb13630.tar.lz
dexon-211cb03f83c8bdfd29af31fd27dc531dfcb13630.tar.xz
dexon-211cb03f83c8bdfd29af31fd27dc531dfcb13630.tar.zst
dexon-211cb03f83c8bdfd29af31fd27dc531dfcb13630.zip
Merge branch 'develop' of github.com-obscure:ethereum/go-ethereum into develop
Diffstat (limited to 'tests')
-rw-r--r--tests/blocktest.go33
1 files changed, 29 insertions, 4 deletions
diff --git a/tests/blocktest.go b/tests/blocktest.go
index 44b459c8d..5719a835b 100644
--- a/tests/blocktest.go
+++ b/tests/blocktest.go
@@ -19,11 +19,11 @@ import (
)
// Block Test JSON Format
-
type btJSON struct {
Blocks []btBlock
GenesisBlockHeader btHeader
Pre map[string]btAccount
+ PostState map[string]btAccount
}
type btAccount struct {
@@ -97,7 +97,7 @@ func LoadBlockTests(file string) (map[string]*BlockTest, error) {
// InsertPreState populates the given database with the genesis
// accounts defined by the test.
-func (t *BlockTest) InsertPreState(db common.Database) error {
+func (t *BlockTest) InsertPreState(db common.Database) (*state.StateDB, error) {
statedb := state.New(common.Hash{}, db)
for addrString, acct := range t.preAccounts {
// XXX: is is worth it checking for errors here?
@@ -119,8 +119,33 @@ func (t *BlockTest) InsertPreState(db common.Database) error {
// sync trie to disk
statedb.Sync()
- if t.Genesis.Root() != statedb.Root() {
- return errors.New("computed state root does not match genesis block")
+ if !bytes.Equal(t.Genesis.Root().Bytes(), statedb.Root().Bytes()) {
+ return nil, errors.New("computed state root does not match genesis block")
+ }
+ return statedb, nil
+}
+
+func (t *BlockTest) ValidatePostState(statedb *state.StateDB) error {
+ for addrString, acct := range t.preAccounts {
+ // XXX: is is worth it checking for errors here?
+ addr, _ := hex.DecodeString(addrString)
+ code, _ := hex.DecodeString(strings.TrimPrefix(acct.Code, "0x"))
+ balance, _ := new(big.Int).SetString(acct.Balance, 0)
+ nonce, _ := strconv.ParseUint(acct.Nonce, 16, 64)
+
+ // address is indirectly verified by the other fields, as it's the db key
+ code2 := statedb.GetCode(common.BytesToAddress(addr))
+ balance2 := statedb.GetBalance(common.BytesToAddress(addr))
+ nonce2 := statedb.GetNonce(common.BytesToAddress(addr))
+ if !bytes.Equal(code2, code) {
+ return fmt.Errorf("account code mismatch, addr, found, expected: ", addrString, hex.EncodeToString(code2), hex.EncodeToString(code))
+ }
+ if balance2.Cmp(balance) != 0 {
+ return fmt.Errorf("account balance mismatch, addr, found, expected: ", addrString, balance2, balance)
+ }
+ if nonce2 != nonce {
+ return fmt.Errorf("account nonce mismatch, addr, found, expected: ", addrString, nonce2, nonce)
+ }
}
return nil
}