Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix failed unit tests #209

Merged
merged 8 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/ronin/consolecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func TestConsoleWelcome(t *testing.T) {

// Verify the actual welcome message to the required template
geth.Expect(`
Welcome to the Geth JavaScript console!
Welcome to the Ronin JavaScript console!

instance: Geth/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}}
instance: ronin/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}}
coinbase: {{.Etherbase}}
at block: 0 ({{niltime}})
datadir: {{.Datadir}}
Expand Down Expand Up @@ -141,9 +141,9 @@ func testAttachWelcome(t *testing.T, geth *testgeth, endpoint, apis string) {

// Verify the actual welcome message to the required template
attach.Expect(`
Welcome to the Geth JavaScript console!
Welcome to the Ronin JavaScript console!

instance: Geth/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}}
instance: ronin/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}}
coinbase: {{etherbase}}
at block: 0 ({{niltime}}){{if ipc}}
datadir: {{datadir}}{{end}}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ronin/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
runGeth(t, append(args, []string{"--exec", "2+2", "console"}...)...).WaitExit()
}
// Retrieve the DAO config flag from the database
path := filepath.Join(datadir, "geth", "chaindata")
path := filepath.Join(datadir, "ronin", "chaindata")
db, err := rawdb.NewLevelDBDatabase(path, 0, 0, "", false)
if err != nil {
t.Fatalf("test %d: failed to open test database: %v", test, err)
Expand Down
1 change: 1 addition & 0 deletions cmd/ronin/testdata/empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions cmd/ronin/testdata/guswallet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"encseed": "26d87f5f2bf9835f9a47eefae571bc09f9107bb13d54ff12a4ec095d01f83897494cf34f7bed2ed34126ecba9db7b62de56c9d7cd136520a0427bfb11b8954ba7ac39b90d4650d3448e31185affcd74226a68f1e94b1108e6e0a4a91cdd83eba",
"ethaddr": "d4584b5f6229b7be90727b0fc8c6b91bb427821f",
"email": "gustav.simonsson@gmail.com",
"btcaddr": "1EVknXyFC68kKNLkh6YnKzW41svSRoaAcx"
}
3 changes: 3 additions & 0 deletions cmd/ronin/testdata/passwords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foobar
foobar
foobar
3 changes: 3 additions & 0 deletions cmd/ronin/testdata/wrong-passwords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrong
wrong
wrong
5 changes: 3 additions & 2 deletions consensus/consortium/common/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package common

import (
"github.com/ethereum/go-ethereum/common"
"reflect"
"testing"

"github.com/ethereum/go-ethereum/common"
)

func TestExtractAddressFromBytes(t *testing.T) {
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestRemoveInvalidRecents(t *testing.T) {
7408557: common.HexToAddress("0xB6bc5bc0410773A3F86B1537ce7495C52e38f88B"),
7408558: common.HexToAddress("0x3B9F2587d55E96276B09b258ac909D809961F6C2"),
}
actual := RemoveOutdatedRecents(recents, 7408559)
actual := RemoveOutdatedRecents(recents, 7408558)
expected := map[uint64]common.Address{
7408557: common.HexToAddress("0xB6bc5bc0410773A3F86B1537ce7495C52e38f88B"),
7408558: common.HexToAddress("0x3B9F2587d55E96276B09b258ac909D809961F6C2"),
Expand Down
2 changes: 1 addition & 1 deletion console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (c *Console) AutoCompleteInput(line string, pos int) (string, []string, str
// Welcome show summary of current Geth instance and some metadata about the
// console's available modules.
func (c *Console) Welcome() {
message := "Welcome to the Geth JavaScript console!\n\n"
message := "Welcome to the Ronin JavaScript console!\n\n"

// Print some generic Geth metadata
if res, err := c.jsre.Run(`
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ func TestInsertReceiptChainRollback(t *testing.T) {
if err != nil {
t.Fatalf("failed to create temp freezer db: %v", err)
}
gspec := Genesis{Config: params.AllEthashProtocolChanges}
gspec := Genesis{Config: params.AllEthashProtocolChanges, BaseFee: big.NewInt(params.InitialBaseFee)}
gspec.MustCommit(ancientDb)
ancientChain, _ := NewBlockChain(ancientDb, nil, gspec.Config, ethash.NewFaker(), vm.Config{}, nil, nil)
defer ancientChain.Stop()
Expand Down
5 changes: 5 additions & 0 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
gen(i, b)
}
if b.engine != nil {
for _, receipt := range b.receipts {
if len(receipt.Logs) != 0 && receipt.Bloom == types.EmptyBloom {
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
}
}
// Finalize and seal the block
block, receipts, _ := b.engine.FinalizeAndAssemble(chainreader, b.header, statedb, b.txs, b.uncles, b.receipts)

Expand Down
47 changes: 25 additions & 22 deletions core/vm/evm_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
package vm

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

type TestOpEvent struct {
feed *event.Feed
}

func (tx *TestOpEvent) Publish(opcode OpCode, order uint64, stateDB StateDB, blockHeight uint64,
blockHash common.Hash, blockTime uint64, hash common.Hash, from, to common.Address, value *big.Int, input []byte, err error) error {
tx.feed.Send(true)
return nil
blockHash common.Hash, blockTime uint64, hash common.Hash, from, to common.Address, value *big.Int, input []byte, err error) *types.InternalTransaction {
return &types.InternalTransaction{
Opcode: opcode.String(),
Order: order,
TransactionHash: hash,
Type: "test",
Value: value,
Input: input,
From: from,
To: to,
Success: err == nil,
Error: "",
Height: blockHeight,
BlockHash: blockHash,
BlockTime: blockTime,
}
}

func TestPublishEvents(t *testing.T) {
var (
internalTxFeed event.Feed
scope event.SubscriptionScope
rs bool
)

ch := make(chan bool, 1)
scope.Track(internalTxFeed.Subscribe(ch))

ctx := BlockContext{
PublishEvents: map[OpCode]OpEvent{
CALL: &TestOpEvent{feed: &internalTxFeed},
CALL: &TestOpEvent{},
},
CurrentTransaction: types.NewTx(&types.LegacyTx{
Nonce: 1,
Expand All @@ -40,14 +43,14 @@ func TestPublishEvents(t *testing.T) {
GasPrice: big.NewInt(0),
Data: []byte(""),
}),
BlockNumber: common.Big0,
Time: common.Big0,
InternalTransactions: &[]*types.InternalTransaction{},
}

evm := &EVM{Context: ctx}
evm.PublishEvent(CALL, 1, common.Address{}, common.Address{}, big.NewInt(0), []byte(""), nil)
select {
case rs = <-ch:
if !rs {
t.Fatal("Publish Event failed")
}
if len(*evm.Context.InternalTransactions) != 1 || (*evm.Context.InternalTransactions)[0].Type != "test" {
t.Error("Failed to publish opcode event")
}
}
4 changes: 2 additions & 2 deletions ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func TestToFilterArg(t *testing.T) {
},
map[string]interface{}{
"address": addresses,
"fromBlock": "pending",
"toBlock": "pending",
"fromBlock": "latest",
"toBlock": "latest",
"topics": [][]common.Hash{},
},
nil,
Expand Down
Loading