diff --git a/blockchain/store.go b/blockchain/store.go index a974009e..e7608b2c 100644 --- a/blockchain/store.go +++ b/blockchain/store.go @@ -1,7 +1,6 @@ package blockchain import ( - "encoding/json" "fmt" "sync" @@ -218,12 +217,12 @@ func calcSeenCommitKey(height int64) []byte { var blockStoreKey = []byte("blockStore") type BlockStoreStateJSON struct { - Height int64 + Height int64 `json:"height"` } // Save persists the blockStore state to the database as JSON. func (bsj BlockStoreStateJSON) Save(db dbm.DB) { - bytes, err := json.Marshal(bsj) + bytes, err := cdc.MarshalJSON(bsj) if err != nil { cmn.PanicSanity(cmn.Fmt("Could not marshal state bytes: %v", err)) } @@ -240,7 +239,7 @@ func LoadBlockStoreStateJSON(db dbm.DB) BlockStoreStateJSON { } } bsj := BlockStoreStateJSON{} - err := json.Unmarshal(bytes, &bsj) + err := cdc.UnmarshalJSON(bytes, &bsj) if err != nil { panic(fmt.Sprintf("Could not unmarshal bytes: %X", bytes)) } diff --git a/blockchain/store_test.go b/blockchain/store_test.go index 8e690e6d..a0d53e0c 100644 --- a/blockchain/store_test.go +++ b/blockchain/store_test.go @@ -31,7 +31,7 @@ func TestNewBlockStore(t *testing.T) { db := db.NewMemDB() db.Set(blockStoreKey, []byte(`{"height": 10000}`)) bs := NewBlockStore(db) - assert.Equal(t, bs.Height(), int64(10000), "failed to properly parse blockstore") + require.Equal(t, int64(10000), bs.Height(), "failed to properly parse blockstore") panicCausers := []struct { data []byte diff --git a/cmd/tendermint/commands/probe_upnp.go b/cmd/tendermint/commands/probe_upnp.go index a37bc360..35c3c354 100644 --- a/cmd/tendermint/commands/probe_upnp.go +++ b/cmd/tendermint/commands/probe_upnp.go @@ -1,7 +1,6 @@ package commands import ( - "encoding/json" "fmt" "github.com/spf13/cobra" @@ -22,7 +21,7 @@ func probeUpnp(cmd *cobra.Command, args []string) error { fmt.Println("Probe failed: ", err) } else { fmt.Println("Probe success!") - jsonBytes, err := json.Marshal(capabilities) + jsonBytes, err := cdc.MarshalJSON(capabilities) if err != nil { return err } diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index 3bcf6556..058bf1e7 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -148,30 +148,30 @@ func TestReactorRecordsBlockParts(t *testing.T) { Round: 0, Part: parts.GetPart(0), } - bz, err := cdc.MarshalBinary(struct{ ConsensusMessage }{msg}) + bz, err := cdc.MarshalBinaryBare(msg) require.NoError(t, err) reactor.Receive(DataChannel, peer, bz) - assert.Equal(t, 1, ps.BlockPartsSent(), "number of block parts sent should have increased by 1") + require.Equal(t, 1, ps.BlockPartsSent(), "number of block parts sent should have increased by 1") // 2) block part with the same height, but different round msg.Round = 1 - bz, err = cdc.MarshalBinary(struct{ ConsensusMessage }{msg}) + bz, err = cdc.MarshalBinaryBare(msg) require.NoError(t, err) reactor.Receive(DataChannel, peer, bz) - assert.Equal(t, 1, ps.BlockPartsSent(), "number of block parts sent should stay the same") + require.Equal(t, 1, ps.BlockPartsSent(), "number of block parts sent should stay the same") // 3) block part from earlier height msg.Height = 1 msg.Round = 0 - bz, err = cdc.MarshalBinary(struct{ ConsensusMessage }{msg}) + bz, err = cdc.MarshalBinaryBare(msg) require.NoError(t, err) reactor.Receive(DataChannel, peer, bz) - assert.Equal(t, 1, ps.BlockPartsSent(), "number of block parts sent should stay the same") + require.Equal(t, 1, ps.BlockPartsSent(), "number of block parts sent should stay the same") } // Test we record votes from other peers @@ -203,7 +203,7 @@ func TestReactorRecordsVotes(t *testing.T) { Type: types.VoteTypePrevote, BlockID: types.BlockID{}, } - bz, err := cdc.MarshalBinary(struct{ ConsensusMessage }{&VoteMessage{vote}}) + bz, err := cdc.MarshalBinaryBare(&VoteMessage{vote}) require.NoError(t, err) reactor.Receive(VoteChannel, peer, bz) @@ -212,7 +212,7 @@ func TestReactorRecordsVotes(t *testing.T) { // 2) vote with the same height, but different round vote.Round = 1 - bz, err = cdc.MarshalBinary(struct{ ConsensusMessage }{&VoteMessage{vote}}) + bz, err = cdc.MarshalBinaryBare(&VoteMessage{vote}) require.NoError(t, err) reactor.Receive(VoteChannel, peer, bz) @@ -222,7 +222,7 @@ func TestReactorRecordsVotes(t *testing.T) { vote.Height = 1 vote.Round = 0 - bz, err = cdc.MarshalBinary(struct{ ConsensusMessage }{&VoteMessage{vote}}) + bz, err = cdc.MarshalBinaryBare(&VoteMessage{vote}) require.NoError(t, err) reactor.Receive(VoteChannel, peer, bz) diff --git a/node/node.go b/node/node.go index 2bcee4b3..83d27cb4 100644 --- a/node/node.go +++ b/node/node.go @@ -2,7 +2,6 @@ package node import ( "bytes" - "encoding/json" "errors" "fmt" "net" @@ -644,7 +643,7 @@ func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) { return nil, errors.New("Genesis doc not found") } var genDoc *types.GenesisDoc - err := json.Unmarshal(bytes, &genDoc) + err := cdc.UnmarshalJSON(bytes, &genDoc) if err != nil { cmn.PanicCrisis(fmt.Sprintf("Failed to load genesis doc due to unmarshaling error: %v (bytes: %X)", err, bytes)) } @@ -653,7 +652,7 @@ func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) { // panics if failed to marshal the given genesis document func saveGenesisDoc(db dbm.DB, genDoc *types.GenesisDoc) { - bytes, err := json.Marshal(genDoc) + bytes, err := cdc.MarshalJSON(genDoc) if err != nil { cmn.PanicCrisis(fmt.Sprintf("Failed to save genesis doc due to marshaling error: %v", err)) } diff --git a/p2p/pex/pex_reactor_test.go b/p2p/pex/pex_reactor_test.go index 16136dc0..b3f29c5b 100644 --- a/p2p/pex/pex_reactor_test.go +++ b/p2p/pex/pex_reactor_test.go @@ -297,7 +297,7 @@ func TestPEXReactorDoesNotAddPrivatePeersToAddrBook(t *testing.T) { size := book.Size() addrs := []*p2p.NetAddress{peer.NodeInfo().NetAddress()} - msg := wire.BinaryBytes(struct{ PexMessage }{&pexAddrsMessage{Addrs: addrs}}) + msg := cdc.MustMarshalBinary(&pexAddrsMessage{Addrs: addrs}) pexR.Receive(PexChannel, peer, msg) assert.Equal(t, size, book.Size()) diff --git a/state/txindex/kv/kv_test.go b/state/txindex/kv/kv_test.go index f81f8ef3..74a2dd7c 100644 --- a/state/txindex/kv/kv_test.go +++ b/state/txindex/kv/kv_test.go @@ -176,12 +176,34 @@ func TestIndexAllTags(t *testing.T) { func txResultWithTags(tags []cmn.KVPair) *types.TxResult { tx := types.Tx("HELLO WORLD") - return &types.TxResult{Height: 1, Index: 0, Tx: tx, Result: abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: tags, Fee: cmn.KI64Pair{Key: []uint8{}, Value: 0}}} + return &types.TxResult{ + Height: 1, + Index: 0, + Tx: tx, + Result: abci.ResponseDeliverTx{ + Data: []byte{0}, + Code: abci.CodeTypeOK, + Log: "", + Tags: tags, + Fee: cmn.KI64Pair{Key: nil, Value: 0}, + }, + } } func benchmarkTxIndex(txsCount int, b *testing.B) { tx := types.Tx("HELLO WORLD") - txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: nil}} + txResult := &types.TxResult{ + Height: 1, + Index: 0, + Tx: tx, + Result: abci.ResponseDeliverTx{ + Data: []byte{0}, + Code: abci.CodeTypeOK, + Log: "", + Tags: []cmn.KVPair{}, + Fee: cmn.KI64Pair{Key: []uint8{}, Value: 0}, + }, + } dir, err := ioutil.TempDir("", "tx_index_db") if err != nil { diff --git a/types/event_bus_test.go b/types/event_bus_test.go index fb2e6574..70a53774 100644 --- a/types/event_bus_test.go +++ b/types/event_bus_test.go @@ -35,7 +35,7 @@ func TestEventBusPublishEventTx(t *testing.T) { done := make(chan struct{}) go func() { for e := range txEventsCh { - edt := e.(TMEventData).Unwrap().(EventDataTx) + edt := e.(EventDataTx) assert.Equal(t, int64(1), edt.Height) assert.Equal(t, uint32(0), edt.Index) assert.Equal(t, tx, edt.Tx)