Skip to content

Commit

Permalink
Merge PR:fix txhash unit test (#1385)
Browse files Browse the repository at this point in the history
* replace animo with RLP for evm transaction

* add tx hash algorithm of ethereum

* format tx hash

* change tx hash to Keccak256 for ethereum compatibility

* update ut with new tx hash

* update etherhash algorithm

* use a sync.Pool for Keccak256 hasher

* add VenusHeight fork

* add VenusHeight to makefile

* add HigherThanVenus function

* set   VenusHeight=8100000 for mainnet

* fix ut

Co-authored-by: xingqiang.yuan <[email protected]>
Co-authored-by: Zhong Qiu <[email protected]>
Co-authored-by: zhongqiuwood <[email protected]>
Co-authored-by: KamiD <[email protected]>
  • Loading branch information
5 people authored Jan 5, 2022
1 parent 9eeb55a commit 25261f0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 37 deletions.
25 changes: 0 additions & 25 deletions app/rpc/namespaces/eth/simulation/evm_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions libs/tendermint/rpc/client/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func TestTx(t *testing.T) {
txHeight := bres.Height
txHash := bres.Hash

anotherTxHash := types.Tx("a different tx").Hash()
anotherTxHash := types.Tx("a different tx").Hash(txHeight)

cases := []struct {
valid bool
Expand Down Expand Up @@ -458,7 +458,7 @@ func TestTxSearch(t *testing.T) {

// pick out the last tx to have something to search for in tests
find := result.Txs[len(result.Txs)-1]
anotherTxHash := types.Tx("a different tx").Hash()
anotherTxHash := types.Tx("a different tx").Hash(0)

for i, c := range GetClients() {
t.Logf("client %d", i)
Expand Down
4 changes: 2 additions & 2 deletions libs/tendermint/state/txindex/indexer_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func TestIndexerServiceIndexesBlocks(t *testing.T) {
time.Sleep(100 * time.Millisecond)

// check the result
res, err := txIndexer.Get(types.Tx("foo").Hash())
res, err := txIndexer.Get(types.Tx("foo").Hash(txResult1.Height))
assert.NoError(t, err)
assert.Equal(t, txResult1, res)
res, err = txIndexer.Get(types.Tx("bar").Hash())
res, err = txIndexer.Get(types.Tx("bar").Hash(txResult2.Height))
assert.NoError(t, err)
assert.Equal(t, txResult2, res)
}
10 changes: 5 additions & 5 deletions libs/tendermint/state/txindex/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestTxIndex(t *testing.T) {
Code: abci.CodeTypeOK, Log: "", Events: nil,
},
}
hash := tx.Hash()
hash := tx.Hash(txResult.Height)

batch := txindex.NewBatch(1)
if err := batch.Add(txResult); err != nil {
Expand All @@ -56,7 +56,7 @@ func TestTxIndex(t *testing.T) {
Code: abci.CodeTypeOK, Log: "", Events: nil,
},
}
hash2 := tx2.Hash()
hash2 := tx2.Hash(txResult2.Height)

err = indexer.Index(txResult2)
require.NoError(t, err)
Expand All @@ -75,7 +75,7 @@ func TestTxSearch(t *testing.T) {
{Type: "account", Attributes: []kv.Pair{{Key: []byte("owner"), Value: []byte("Ivan")}}},
{Type: "", Attributes: []kv.Pair{{Key: []byte("not_allowed"), Value: []byte("Vlad")}}},
})
hash := txResult.Tx.Hash()
hash := txResult.Tx.Hash(txResult.Height)

err := indexer.Index(txResult)
require.NoError(t, err)
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestTxSearchDeprecatedIndexing(t *testing.T) {
txResult1 := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []kv.Pair{{Key: []byte("number"), Value: []byte("1")}}},
})
hash1 := txResult1.Tx.Hash()
hash1 := txResult1.Tx.Hash(txResult1.Height)

err := indexer.Index(txResult1)
require.NoError(t, err)
Expand All @@ -171,7 +171,7 @@ func TestTxSearchDeprecatedIndexing(t *testing.T) {
txResult2 := txResultWithEvents(nil)
txResult2.Tx = types.Tx("HELLO WORLD 2")

hash2 := txResult2.Tx.Hash()
hash2 := txResult2.Tx.Hash(txResult2.Height)
b := indexer.store.NewBatch()

rawBytes, err := cdc.MarshalBinaryBare(txResult2)
Expand Down
2 changes: 1 addition & 1 deletion libs/tendermint/types/event_bus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestEventBusPublishEventTx(t *testing.T) {
}

// PublishEventTx adds 3 composite keys, so the query below should work
query := fmt.Sprintf("tm.event='Tx' AND tx.height=1 AND tx.hash='%X' AND testType.baz=1", tx.Hash())
query := fmt.Sprintf("tm.event='Tx' AND tx.height=1 AND tx.hash='%X' AND testType.baz=1", tx.Hash(0))
txsSub, err := eventBus.Subscribe(context.Background(), "test", tmquery.MustParse(query))
require.NoError(t, err)

Expand Down
5 changes: 3 additions & 2 deletions libs/tendermint/types/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

func TestQueryTxFor(t *testing.T) {
tx := Tx("foo")
height := int64(0)
assert.Equal(t,
fmt.Sprintf("tm.event='Tx' AND tx.hash='%X'", tx.Hash()),
EventQueryTxFor(tx).String(),
fmt.Sprintf("tm.event='Tx' AND tx.hash='%X'", tx.Hash(height)),
EventQueryTxFor(tx, height).String(),
)
}

Expand Down

0 comments on commit 25261f0

Please sign in to comment.