From 9f18c80abcbfd46b457267490516ab81b295ebc9 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Tue, 28 Jul 2015 12:13:50 -0700 Subject: [PATCH] Fixes #121 --- state/tx_cache.go | 2 +- state/tx_cache_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 state/tx_cache_test.go diff --git a/state/tx_cache.go b/state/tx_cache.go index b4afcc9d..2e4d1723 100644 --- a/state/tx_cache.go +++ b/state/tx_cache.go @@ -174,7 +174,7 @@ func toStateAccount(acc *vm.Account) *acm.Account { if acc.StorageRoot.IsZero() { storageRoot = nil } else { - storageRoot = acc.StorageRoot.Bytes() + storageRoot = acc.StorageRoot.Postfix(20) } return &acm.Account{ Address: acc.Address.Postfix(20), diff --git a/state/tx_cache_test.go b/state/tx_cache_test.go new file mode 100644 index 00000000..028f977e --- /dev/null +++ b/state/tx_cache_test.go @@ -0,0 +1,24 @@ +package state + +import ( + "bytes" + "testing" + + . "github.com/tendermint/tendermint/common" + "github.com/tendermint/tendermint/wire" +) + +func TestStateToFromVMAccount(t *testing.T) { + acmAcc1, _ := RandAccount(true, 456) + acmAcc1.StorageRoot = RandBytes(20) + vmAcc := toVMAccount(acmAcc1) + acmAcc2 := toStateAccount(vmAcc) + + acmAcc1Bytes := wire.BinaryBytes(acmAcc1) + acmAcc2Bytes := wire.BinaryBytes(acmAcc2) + if !bytes.Equal(acmAcc1Bytes, acmAcc2Bytes) { + t.Errorf("Unexpected account wire bytes\n%X vs\n%X", + acmAcc1Bytes, acmAcc2Bytes) + } + +}