Add more tests
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
227b9f7e18
commit
35575263cb
@ -143,7 +143,6 @@ func (ia InitActor) Exec(act *types.Actor, vmctx types.VMContext, p *ExecParams)
|
|||||||
return types.InvokeRet{}, errors.Wrap(err, "inserting new actor into state tree")
|
return types.InvokeRet{}, errors.Wrap(err, "inserting new actor into state tree")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("PARAMS: ", string(p.Params))
|
|
||||||
_, _, err = vmctx.Send(idAddr, 0, vmctx.Message().Value, p.Params)
|
_, _, err = vmctx.Send(idAddr, 0, vmctx.Message().Value, p.Params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.InvokeRet{}, err
|
return types.InvokeRet{}, err
|
||||||
|
65
chain/actors/actor_storagemarket_test.go
Normal file
65
chain/actors/actor_storagemarket_test.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package actors_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/filecoin-project/go-lotus/chain/actors"
|
||||||
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStorageMarketCreateMiner(t *testing.T) {
|
||||||
|
h := NewHarness(t)
|
||||||
|
var outaddr address.Address
|
||||||
|
h.Steps = []Step{
|
||||||
|
{
|
||||||
|
M: types.Message{
|
||||||
|
To: StorageMarketAddress,
|
||||||
|
From: h.From,
|
||||||
|
Method: 1,
|
||||||
|
GasPrice: types.NewInt(1),
|
||||||
|
GasLimit: types.NewInt(1),
|
||||||
|
Value: types.NewInt(0),
|
||||||
|
Params: h.DumpObject(&StorageMinerConstructorParams{
|
||||||
|
Worker: h.Third,
|
||||||
|
SectorSize: types.NewInt(SectorSize),
|
||||||
|
PeerID: "fakepeerid",
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
Ret: func(t *testing.T, ret *types.MessageReceipt) {
|
||||||
|
if ret.ExitCode != 0 {
|
||||||
|
t.Fatal("invokation failed: ", ret.ExitCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
outaddr, err = address.NewFromBytes(ret.Return)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if outaddr.String() != "t0102" {
|
||||||
|
t.Fatal("hold up")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
state := h.Execute()
|
||||||
|
act, err := state.GetActor(outaddr)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if act.Code != StorageMinerCodeCid {
|
||||||
|
t.Fatalf("Expected correct code, got %s, instead of %s", act.Code, StorageMinerCodeCid)
|
||||||
|
}
|
||||||
|
hblock, err := h.bs.Get(act.Head)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
smas := &StorageMinerActorState{}
|
||||||
|
cbor.DecodeInto(hblock.RawData(), smas)
|
||||||
|
if smas.Owner != h.From {
|
||||||
|
t.Fatalf("Owner should be %s, but is %s", h.From, smas.Owner)
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@ import (
|
|||||||
type Harness struct {
|
type Harness struct {
|
||||||
Steps []Step
|
Steps []Step
|
||||||
From address.Address
|
From address.Address
|
||||||
|
Third address.Address
|
||||||
|
|
||||||
currStep int
|
currStep int
|
||||||
|
|
||||||
@ -41,10 +42,12 @@ func NewHarness(t *testing.T) *Harness {
|
|||||||
|
|
||||||
from := blsaddr(0)
|
from := blsaddr(0)
|
||||||
maddr := blsaddr(1)
|
maddr := blsaddr(1)
|
||||||
|
third := blsaddr(1)
|
||||||
|
|
||||||
actors := map[address.Address]types.BigInt{
|
actors := map[address.Address]types.BigInt{
|
||||||
from: types.NewInt(1000000),
|
from: types.NewInt(1000000),
|
||||||
maddr: types.NewInt(0),
|
maddr: types.NewInt(0),
|
||||||
|
third: types.NewInt(1000),
|
||||||
}
|
}
|
||||||
st, err := chain.MakeInitialStateTree(h.bs, actors)
|
st, err := chain.MakeInitialStateTree(h.bs, actors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -62,8 +65,9 @@ func NewHarness(t *testing.T) *Harness {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
h.actors = []address.Address{from, maddr}
|
h.actors = []address.Address{from, maddr, third}
|
||||||
h.From = from
|
h.From = from
|
||||||
|
h.Third = third
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +75,11 @@ func (h *Harness) Execute() *chain.StateTree {
|
|||||||
for i, step := range h.Steps {
|
for i, step := range h.Steps {
|
||||||
h.currStep = i
|
h.currStep = i
|
||||||
ret, err := h.vm.ApplyMessage(&step.M)
|
ret, err := h.vm.ApplyMessage(&step.M)
|
||||||
step.Err(h.t, err)
|
if step.Err != nil {
|
||||||
|
step.Err(h.t, err)
|
||||||
|
} else {
|
||||||
|
h.NoError(h.t, err)
|
||||||
|
}
|
||||||
step.Ret(h.t, ret)
|
step.Ret(h.t, ret)
|
||||||
}
|
}
|
||||||
stateroot, err := h.vm.Flush(context.TODO())
|
stateroot, err := h.vm.Flush(context.TODO())
|
||||||
@ -118,9 +126,6 @@ func TestVMInvokeHarness(t *testing.T) {
|
|||||||
Value: types.NewInt(0),
|
Value: types.NewInt(0),
|
||||||
},
|
},
|
||||||
Ret: func(t *testing.T, ret *types.MessageReceipt) {
|
Ret: func(t *testing.T, ret *types.MessageReceipt) {
|
||||||
if ret == nil {
|
|
||||||
t.Fatal("ret is nil")
|
|
||||||
}
|
|
||||||
if ret.ExitCode != 0 {
|
if ret.ExitCode != 0 {
|
||||||
t.Fatal("invocation failed: ", ret.ExitCode)
|
t.Fatal("invocation failed: ", ret.ExitCode)
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,6 @@ func (st *StateTree) GetActor(addr address.Address) (*types.Actor, error) {
|
|||||||
|
|
||||||
func (st *StateTree) Flush() (cid.Cid, error) {
|
func (st *StateTree) Flush() (cid.Cid, error) {
|
||||||
for addr, act := range st.actorcache {
|
for addr, act := range st.actorcache {
|
||||||
fmt.Println("FLUSHING ACTOR CACHE: ", addr.String(), act.Head)
|
|
||||||
if err := st.root.Set(context.TODO(), string(addr.Bytes()), act); err != nil {
|
if err := st.root.Set(context.TODO(), string(addr.Bytes()), act); err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
|
10
chain/vm.go
10
chain/vm.go
@ -75,8 +75,16 @@ func (vmc *VMContext) Ipld() *hamt.CborIpldStore {
|
|||||||
|
|
||||||
// Send allows the current execution context to invoke methods on other actors in the system
|
// Send allows the current execution context to invoke methods on other actors in the system
|
||||||
func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt, params []byte) ([]byte, uint8, error) {
|
func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt, params []byte) ([]byte, uint8, error) {
|
||||||
|
|
||||||
|
var from address.Address
|
||||||
|
if method == 0 {
|
||||||
|
// is constructor
|
||||||
|
from = vmc.msg.From
|
||||||
|
} else {
|
||||||
|
from = vmc.msg.To
|
||||||
|
}
|
||||||
msg := &types.Message{
|
msg := &types.Message{
|
||||||
From: vmc.msg.From,
|
From: from,
|
||||||
To: to,
|
To: to,
|
||||||
Method: method,
|
Method: method,
|
||||||
Value: value,
|
Value: value,
|
||||||
|
Loading…
Reference in New Issue
Block a user