aboutsummaryrefslogtreecommitdiffstats
path: root/tests/state_test_util.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-06-11 03:02:16 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-06-19 04:15:08 +0800
commit24554629b162d20a1f945386a45e3221c58adc2b (patch)
tree6fa08ffc20d2d8f7cec6417e444576c779a73f39 /tests/state_test_util.go
parent7c6ef0ddac91564f31ef852fd4ef1e821db17c2e (diff)
downloaddexon-24554629b162d20a1f945386a45e3221c58adc2b.tar
dexon-24554629b162d20a1f945386a45e3221c58adc2b.tar.gz
dexon-24554629b162d20a1f945386a45e3221c58adc2b.tar.bz2
dexon-24554629b162d20a1f945386a45e3221c58adc2b.tar.lz
dexon-24554629b162d20a1f945386a45e3221c58adc2b.tar.xz
dexon-24554629b162d20a1f945386a45e3221c58adc2b.tar.zst
dexon-24554629b162d20a1f945386a45e3221c58adc2b.zip
DRY log check
Diffstat (limited to 'tests/state_test_util.go')
-rw-r--r--tests/state_test_util.go72
1 files changed, 40 insertions, 32 deletions
diff --git a/tests/state_test_util.go b/tests/state_test_util.go
index 1f481147e..91a8367e7 100644
--- a/tests/state_test_util.go
+++ b/tests/state_test_util.go
@@ -75,22 +75,20 @@ func RunStateTest(p string, t *testing.T) {
}
}
+ // check post state
for addr, account := range test.Post {
obj := statedb.GetStateObject(common.HexToAddress(addr))
if obj == nil {
continue
}
- // if len(test.Exec) == 0 {
if obj.Balance().Cmp(common.Big(account.Balance)) != 0 {
t.Errorf("%s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address().Bytes()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(common.Big(account.Balance), obj.Balance()))
}
- // if obj.Nonce() != common.String2Big(account.Nonce).Uint64() {
- // t.Errorf("%s's : (%x) nonce failed. Expected %v, got %v\n", name, obj.Address().Bytes()[:4], account.Nonce, obj.Nonce())
- // }
-
- // }
+ if obj.Nonce() != common.String2Big(account.Nonce).Uint64() {
+ t.Errorf("%s's : (%x) nonce failed. Expected %v, got %v\n", name, obj.Address().Bytes()[:4], account.Nonce, obj.Nonce())
+ }
for addr, value := range account.Storage {
v := obj.GetState(common.HexToHash(addr)).Bytes()
@@ -108,41 +106,51 @@ func RunStateTest(p string, t *testing.T) {
t.Errorf("%s's : Post state root error. Expected %s, got %x", name, test.PostStateRoot, statedb.Root())
}
+ // check logs
if len(test.Logs) > 0 {
- if len(test.Logs) != len(logs) {
- t.Errorf("log length mismatch. Expected %d, got %d", len(test.Logs), len(logs))
- } else {
- for i, log := range test.Logs {
- if common.HexToAddress(log.AddressF) != logs[i].Address {
- t.Errorf("'%s' log address expected %v got %x", name, log.AddressF, logs[i].Address)
- }
+ lerr := CheckLogs(test.Logs, logs, t)
+ if lerr != nil {
+ t.Errorf("'%s' ", name, lerr.Error())
+ }
+ }
- if !bytes.Equal(logs[i].Data, common.FromHex(log.DataF)) {
- t.Errorf("'%s' log data expected %v got %x", name, log.DataF, logs[i].Data)
- }
+ fmt.Println("State test passed: ", name)
+ //fmt.Println(string(statedb.Dump()))
+ }
+ // logger.Flush()
+}
- if len(log.TopicsF) != len(logs[i].Topics) {
- t.Errorf("'%s' log topics length expected %d got %d", name, len(log.TopicsF), logs[i].Topics)
- } else {
- for j, topic := range log.TopicsF {
- if common.HexToHash(topic) != logs[i].Topics[j] {
- t.Errorf("'%s' log topic[%d] expected %v got %x", name, j, topic, logs[i].Topics[j])
- }
- }
- }
- genBloom := common.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
+func CheckLogs(tlog []Log, logs state.Logs, t *testing.T) error {
+
+ if len(tlog) != len(logs) {
+ return fmt.Errorf("log length mismatch. Expected %d, got %d", len(tlog), len(logs))
+ } else {
+ for i, log := range tlog {
+ if common.HexToAddress(log.AddressF) != logs[i].Address {
+ return fmt.Errorf("log address expected %v got %x", log.AddressF, logs[i].Address)
+ }
- if !bytes.Equal(genBloom, common.Hex2Bytes(log.BloomF)) {
- t.Errorf("'%s' bloom mismatch", name)
+ if !bytes.Equal(logs[i].Data, common.FromHex(log.DataF)) {
+ return fmt.Errorf("log data expected %v got %x", log.DataF, logs[i].Data)
+ }
+
+ if len(log.TopicsF) != len(logs[i].Topics) {
+ return fmt.Errorf("log topics length expected %d got %d", len(log.TopicsF), logs[i].Topics)
+ } else {
+ for j, topic := range log.TopicsF {
+ if common.HexToHash(topic) != logs[i].Topics[j] {
+ return fmt.Errorf("log topic[%d] expected %v got %x", j, topic, logs[i].Topics[j])
}
}
}
- }
+ genBloom := common.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
- fmt.Println("State test passed: ", name)
- //fmt.Println(string(statedb.Dump()))
+ if !bytes.Equal(genBloom, common.Hex2Bytes(log.BloomF)) {
+ return fmt.Errorf("bloom mismatch")
+ }
+ }
}
- // logger.Flush()
+ return nil
}
func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.Logs, *big.Int, error) {