2019-09-26 20:47:34 +00:00
|
|
|
package miner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/address"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2019-09-26 20:47:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func mustIDAddr(i uint64) address.Address {
|
|
|
|
a, err := address.NewIDAddress(i)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMessageFiltering(t *testing.T) {
|
|
|
|
ctx := context.TODO()
|
|
|
|
a1 := mustIDAddr(1)
|
|
|
|
a2 := mustIDAddr(2)
|
|
|
|
|
|
|
|
actors := map[address.Address]*types.Actor{
|
|
|
|
a1: &types.Actor{
|
|
|
|
Nonce: 3,
|
|
|
|
Balance: types.NewInt(1200),
|
|
|
|
},
|
|
|
|
a2: &types.Actor{
|
|
|
|
Nonce: 1,
|
|
|
|
Balance: types.NewInt(1000),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-12-03 06:41:28 +00:00
|
|
|
af := func(ctx context.Context, addr address.Address, ts *types.TipSet) (uint64, *types.BigInt, error) {
|
|
|
|
return actors[addr].Nonce, &actors[addr].Balance, nil
|
2019-09-26 20:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msgs := []types.Message{
|
|
|
|
types.Message{
|
|
|
|
From: a1,
|
2019-10-14 04:32:55 +00:00
|
|
|
To: a1,
|
2019-09-26 20:47:34 +00:00
|
|
|
Nonce: 3,
|
|
|
|
Value: types.NewInt(500),
|
|
|
|
GasLimit: types.NewInt(50),
|
|
|
|
GasPrice: types.NewInt(1),
|
|
|
|
},
|
|
|
|
types.Message{
|
|
|
|
From: a1,
|
2019-10-14 04:32:55 +00:00
|
|
|
To: a1,
|
2019-09-26 20:47:34 +00:00
|
|
|
Nonce: 4,
|
|
|
|
Value: types.NewInt(500),
|
|
|
|
GasLimit: types.NewInt(50),
|
|
|
|
GasPrice: types.NewInt(1),
|
|
|
|
},
|
|
|
|
types.Message{
|
|
|
|
From: a2,
|
2019-10-14 04:32:55 +00:00
|
|
|
To: a1,
|
2019-09-26 20:47:34 +00:00
|
|
|
Nonce: 1,
|
|
|
|
Value: types.NewInt(800),
|
|
|
|
GasLimit: types.NewInt(100),
|
|
|
|
GasPrice: types.NewInt(1),
|
|
|
|
},
|
|
|
|
types.Message{
|
|
|
|
From: a2,
|
2019-10-14 04:32:55 +00:00
|
|
|
To: a1,
|
2019-09-26 20:47:34 +00:00
|
|
|
Nonce: 0,
|
|
|
|
Value: types.NewInt(800),
|
|
|
|
GasLimit: types.NewInt(100),
|
|
|
|
GasPrice: types.NewInt(1),
|
|
|
|
},
|
|
|
|
types.Message{
|
|
|
|
From: a2,
|
2019-10-14 04:32:55 +00:00
|
|
|
To: a1,
|
2019-09-26 20:47:34 +00:00
|
|
|
Nonce: 2,
|
|
|
|
Value: types.NewInt(150),
|
|
|
|
GasLimit: types.NewInt(100),
|
|
|
|
GasPrice: types.NewInt(1),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
outmsgs, err := selectMessages(ctx, af, &MiningBase{}, wrapMsgs(msgs))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(outmsgs) != 3 {
|
|
|
|
t.Fatal("filtering didnt work as expected")
|
|
|
|
}
|
|
|
|
|
|
|
|
m1 := outmsgs[2].Message
|
|
|
|
if m1.From != msgs[2].From || m1.Nonce != msgs[2].Nonce {
|
|
|
|
t.Fatal("filtering bad")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func wrapMsgs(msgs []types.Message) []*types.SignedMessage {
|
|
|
|
var out []*types.SignedMessage
|
|
|
|
for _, m := range msgs {
|
|
|
|
out = append(out, &types.SignedMessage{Message: m})
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|