Skip to content

Commit

Permalink
Fix some messagepool tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Jakub Sztandera committed Aug 6, 2020
1 parent 6562b7a commit d676584
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
2 changes: 1 addition & 1 deletion chain/messagepool/messagepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (tma *testMpoolAPI) PubSubPublish(string, []byte) error {
func (tma *testMpoolAPI) StateGetActor(addr address.Address, ts *types.TipSet) (*types.Actor, error) {
balance, ok := tma.balance[addr]
if !ok {
balance = types.NewInt(90000000)
balance = types.NewInt(1000e6)
tma.balance[addr] = balance
}
return &types.Actor{
Expand Down
15 changes: 1 addition & 14 deletions chain/messagepool/selection.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package messagepool

import (
"context"
"math/big"
"sort"
"time"
Expand Down Expand Up @@ -233,19 +232,7 @@ func (mp *MessagePool) getPendingMessages(curTs, ts *types.TipSet) (map[address.
}

func (mp *MessagePool) getGasReward(msg *types.SignedMessage, ts *types.TipSet) *big.Int {
al := func(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.Actor, error) {
return mp.api.StateGetActor(addr, ts)
}
gasUsed, err := gasguess.GuessGasUsed(context.TODO(), types.EmptyTSK, msg, al)
if err != nil {
gasUsed = int64(gasguess.MaxGas)
if gasUsed > msg.Message.GasLimit/2 {
gasUsed = msg.Message.GasLimit / 2
}
// if we start seeing this warning we may have a problem with spammers!
log.Warnf("Cannot guess gas usage for message: %s; using %d", err, gasUsed)
}
gasReward := abig.Mul(msg.Message.GasPrice, types.NewInt(uint64(gasUsed)))
gasReward := abig.Mul(msg.Message.GasPremium, types.NewInt(uint64(msg.Message.GasLimit)))
return gasReward.Int
}

Expand Down
15 changes: 8 additions & 7 deletions chain/messagepool/selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import (

func makeTestMessage(w *wallet.Wallet, from, to address.Address, nonce uint64, gasLimit int64, gasPrice uint64) *types.SignedMessage {
msg := &types.Message{
From: from,
To: to,
Method: 2,
Value: types.FromFil(0),
Nonce: nonce,
GasLimit: gasLimit,
GasPrice: types.NewInt(gasPrice),
From: from,
To: to,
Method: 2,
Value: types.FromFil(0),
Nonce: nonce,
GasLimit: gasLimit,
GasFeeCap: types.NewInt(gasPrice + 100),
GasPremium: types.NewInt(gasPrice),
}
sig, err := w.Sign(context.TODO(), from, msg.Cid().Bytes())
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions chain/types/mock/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ func Address(i uint64) address.Address {

func MkMessage(from, to address.Address, nonce uint64, w *wallet.Wallet) *types.SignedMessage {
msg := &types.Message{
To: to,
From: from,
Value: types.NewInt(1),
Nonce: nonce,
GasLimit: 1000000,
GasPrice: types.NewInt(0),
To: to,
From: from,
Value: types.NewInt(1),
Nonce: nonce,
GasLimit: 1000000,
GasFeeCap: types.NewInt(100),
GasPremium: types.NewInt(1),
}

sig, err := w.Sign(context.TODO(), from, msg.Cid().Bytes())
Expand Down

0 comments on commit d676584

Please sign in to comment.