refactor: add default TestVector to TestDriver (#208)

This PR adds a `TestVector` to the `TestDriver` so that test driver methods that apply messages can be recorded in the test vector.

refs #194
This commit is contained in:
Alan Shaw 2020-08-07 13:47:16 +01:00 committed by GitHub
parent 7d118e1b12
commit 81ea0ec5f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 123 additions and 136 deletions

View File

@ -44,7 +44,7 @@ func MustNewActorAddr(data string) addr.Address {
return address
}
func MustIdFromAddress(a addr.Address) uint64 {
func MustIDFromAddress(a addr.Address) uint64 {
if a.Protocol() != addr.ID {
panic("must be ID protocol address")
}

View File

@ -120,7 +120,7 @@ func (d *StateDriver) newMinerAccountActor(sealProofType abi_spec.RegisteredSeal
// creat a miner, owner, and its worker
minerOwnerPk, minerOwnerID := d.NewAccountActor(address.SECP256K1, big_spec.NewInt(1_000_000_000))
minerWorkerPk, minerWorkerID := d.NewAccountActor(address.BLS, big_spec.Zero())
expectedMinerActorIDAddress := chain.MustNewIDAddr(chain.MustIdFromAddress(minerWorkerID) + 1)
expectedMinerActorIDAddress := chain.MustNewIDAddr(chain.MustIDFromAddress(minerWorkerID) + 1)
minerActorAddrs := computeInitActorExecReturn(minerWorkerPk, 0, 1, expectedMinerActorIDAddress)
d.minerInfo = &MinerInfo{

View File

@ -44,6 +44,7 @@ import (
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/oni/tvx/chain"
vtypes "github.com/filecoin-project/oni/tvx/chain/types"
"github.com/filecoin-project/oni/tvx/schema"
)
var (
@ -235,6 +236,25 @@ func NewTestDriver() *TestDriver {
checkRet := true
config := NewConfig(checkExit, checkRet)
vector := schema.TestVector{
Class: schema.ClassMessage,
Selector: "",
Meta: &schema.Metadata{
ID: "TK",
Version: "TK",
Gen: schema.GenerationData{
Source: "TK",
Version: "TK",
},
},
Pre: &schema.Preconditions{
StateTree: &schema.StateTree{},
},
Post: &schema.Postconditions{
StateTree: &schema.StateTree{},
},
}
return &TestDriver{
StateDriver: sd,
@ -244,6 +264,7 @@ func NewTestDriver() *TestDriver {
SysCalls: syscalls,
applier: applier,
Vector: &vector,
}
}
@ -265,6 +286,9 @@ type TestDriver struct {
Config *Config
SysCalls *ChainValidationSysCalls
// Vector is the test vector that is used when methods are called on the
// driver that apply messages.
Vector *schema.TestVector
}
//

View File

@ -14,6 +14,7 @@ import (
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
"github.com/filecoin-project/specs-actors/actors/util/adt"
"github.com/filecoin-project/oni/tvx/schema"
"github.com/filecoin-project/oni/tvx/state"
)
@ -62,7 +63,7 @@ func runExamineCmd(_ *cli.Context) error {
return err
}
var tv TestVector
var tv schema.TestVector
if err := json.NewDecoder(file).Decode(&tv); err != nil {
return err
}

View File

@ -15,6 +15,7 @@ import (
"github.com/urfave/cli/v2"
"github.com/filecoin-project/oni/tvx/lotus"
"github.com/filecoin-project/oni/tvx/schema"
)
var execLotusFlags struct {
@ -44,7 +45,7 @@ func runExecLotus(_ *cli.Context) error {
var (
dec = json.NewDecoder(file)
tv TestVector
tv schema.TestVector
)
if err = dec.Decode(&tv); err != nil {
@ -55,7 +56,7 @@ func runExecLotus(_ *cli.Context) error {
default:
dec := json.NewDecoder(os.Stdin)
for {
var tv TestVector
var tv schema.TestVector
err := dec.Decode(&tv)
if err == io.EOF {
@ -73,7 +74,7 @@ func runExecLotus(_ *cli.Context) error {
}
}
func executeTestVector(tv TestVector) error {
func executeTestVector(tv schema.TestVector) error {
fmt.Println("executing test vector")
switch tv.Class {
case "message":

View File

@ -14,6 +14,7 @@ import (
"github.com/urfave/cli/v2"
"github.com/filecoin-project/oni/tvx/lotus"
"github.com/filecoin-project/oni/tvx/schema"
"github.com/filecoin-project/oni/tvx/state"
)
@ -178,27 +179,27 @@ func runExtractMsg(c *cli.Context) error {
}
// Write out the test vector.
vector := TestVector{
Class: ClassMessage,
vector := schema.TestVector{
Class: schema.ClassMessage,
Selector: "",
Meta: &Metadata{
Meta: &schema.Metadata{
ID: "TK",
Version: "TK",
Gen: GenerationData{
Gen: schema.GenerationData{
Source: "TK",
Version: version.String(),
},
},
CAR: out.Bytes(),
Pre: &Preconditions{
Pre: &schema.Preconditions{
Epoch: execTs.Height(),
StateTree: &StateTree{
StateTree: &schema.StateTree{
RootCID: preroot,
},
},
ApplyMessages: []Message{{Bytes: msgBytes}},
Post: &Postconditions{
StateTree: &StateTree{
ApplyMessages: []schema.Message{{Bytes: msgBytes}},
Post: &schema.Postconditions{
StateTree: &schema.StateTree{
RootCID: postroot,
},
},

View File

@ -1,4 +1,4 @@
package main
package schema
import (
"encoding/hex"

View File

@ -15,11 +15,12 @@ import (
"github.com/filecoin-project/oni/tvx/chain"
"github.com/filecoin-project/oni/tvx/drivers"
"github.com/filecoin-project/oni/tvx/schema"
)
var suiteMessagesCmd = &cli.Command{
Name: "suite-messages",
Description: "",
Description: "generate test vectors from the messages test suite adapted from github.com/filecoin-project/chain-validation",
Action: suiteMessages,
}
@ -90,8 +91,6 @@ func MessageTest_AccountActorCreation() error {
err := func() error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
existingAccountAddr, _ := td.NewAccountActor(tc.existingActorType, tc.existingActorBal)
preroot := td.GetStateRoot()
@ -101,7 +100,7 @@ func MessageTest_AccountActorCreation() error {
if err != nil {
return err
}
v.ApplyMessages = []Message{{Bytes: b}}
td.Vector.ApplyMessages = []schema.Message{{Bytes: b}}
result := td.ApplyFailure(
msg,
tc.expExitCode,
@ -115,13 +114,13 @@ func MessageTest_AccountActorCreation() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}
@ -139,8 +138,6 @@ func MessageTest_AccountActorCreation() error {
func MessageTest_InitActorSequentialIDAddressCreate() error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
var initialBal = abi_spec.NewTokenAmount(200_000_000_000)
var toSend = abi_spec.NewTokenAmount(10_000)
@ -148,8 +145,8 @@ func MessageTest_InitActorSequentialIDAddressCreate() error {
receiver, receiverID := td.NewAccountActor(drivers.SECP, initialBal)
firstPaychAddr := chain.MustNewIDAddr(chain.MustIdFromAddress(receiverID) + 1)
secondPaychAddr := chain.MustNewIDAddr(chain.MustIdFromAddress(receiverID) + 2)
firstPaychAddr := chain.MustNewIDAddr(chain.MustIDFromAddress(receiverID) + 1)
secondPaychAddr := chain.MustNewIDAddr(chain.MustIDFromAddress(receiverID) + 2)
firstInitRet := td.ComputeInitActorExecReturn(sender, 0, 0, firstPaychAddr)
secondInitRet := td.ComputeInitActorExecReturn(sender, 1, 0, secondPaychAddr)
@ -166,7 +163,7 @@ func MessageTest_InitActorSequentialIDAddressCreate() error {
if err != nil {
return err
}
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: b1})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: b1})
msg2 := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(1))
td.ApplyExpect(
@ -178,40 +175,19 @@ func MessageTest_InitActorSequentialIDAddressCreate() error {
if err != nil {
return err
}
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: b2})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: b2})
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}
return nil
}
func newEmptyMessageVector() TestVector {
return TestVector{
Class: ClassMessage,
Selector: "",
Meta: &Metadata{
ID: "TK",
Version: "TK",
Gen: GenerationData{
Source: "TK",
Version: "TK",
},
},
Pre: &Preconditions{
StateTree: &StateTree{},
},
Post: &Postconditions{
StateTree: &StateTree{},
},
}
}

View File

@ -12,6 +12,7 @@ import (
"github.com/filecoin-project/oni/tvx/chain"
"github.com/filecoin-project/oni/tvx/drivers"
"github.com/filecoin-project/oni/tvx/schema"
)
func MessageTest_MessageApplicationEdgecases() error {
@ -21,13 +22,12 @@ func MessageTest_MessageApplicationEdgecases() error {
err := func(testname string) error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
preroot := td.GetStateRoot()
msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(1), chain.GasLimit(8))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyFailure(
msg,
@ -35,13 +35,13 @@ func MessageTest_MessageApplicationEdgecases() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}
@ -54,12 +54,11 @@ func MessageTest_MessageApplicationEdgecases() error {
err = func(testname string) error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
preroot := td.GetStateRoot()
msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// Expect Message application to fail due to lack of gas
td.ApplyFailure(
@ -68,7 +67,7 @@ func MessageTest_MessageApplicationEdgecases() error {
unknown := chain.MustNewIDAddr(10000000)
msg = td.MessageProducer.Transfer(unknown, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// Expect Message application to fail due to lack of gas when sender is unknown
td.ApplyFailure(
@ -77,13 +76,13 @@ func MessageTest_MessageApplicationEdgecases() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}
@ -96,8 +95,6 @@ func MessageTest_MessageApplicationEdgecases() error {
err = func(testname string) error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
preroot := td.GetStateRoot()
@ -109,7 +106,7 @@ func MessageTest_MessageApplicationEdgecases() error {
newAccountA := chain.MustNewSECP256K1Addr("1")
msg := td.MessageProducer.Transfer(alice, newAccountA, chain.Value(transferAmnt), chain.Nonce(aliceNonceF()))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// get the "true" gas cost of applying the message
result := td.ApplyOk(msg)
@ -120,7 +117,7 @@ func MessageTest_MessageApplicationEdgecases() error {
newAccountB := chain.MustNewSECP256K1Addr("2")
for tryGas := trueGas - gasStep; tryGas > 0; tryGas -= gasStep {
msg := td.MessageProducer.Transfer(alice, newAccountB, chain.Value(transferAmnt), chain.Nonce(aliceNonceF()), chain.GasPrice(1), chain.GasLimit(tryGas))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyFailure(
msg,
@ -130,13 +127,13 @@ func MessageTest_MessageApplicationEdgecases() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}
@ -149,14 +146,12 @@ func MessageTest_MessageApplicationEdgecases() error {
err = func(testname string) error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
preroot := td.GetStateRoot()
msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(1))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// Expect Message application to fail due to callseqnum being invalid: 1 instead of 0
td.ApplyFailure(
@ -165,7 +160,7 @@ func MessageTest_MessageApplicationEdgecases() error {
unknown := chain.MustNewIDAddr(10000000)
msg = td.MessageProducer.Transfer(unknown, alice, chain.Value(transferAmnt), chain.Nonce(1))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// Expect message application to fail due to unknow actor when call seq num is also incorrect
td.ApplyFailure(
@ -174,13 +169,13 @@ func MessageTest_MessageApplicationEdgecases() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}
@ -193,8 +188,6 @@ func MessageTest_MessageApplicationEdgecases() error {
err = func(testname string) error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
const pcTimeLock = abi_spec.ChainEpoch(10)
const pcLane = uint64(123)
const pcNonce = uint64(1)
@ -212,13 +205,13 @@ func MessageTest_MessageApplicationEdgecases() error {
receiver, receiverID := td.NewAccountActor(drivers.SECP, initialBal)
// the _expected_ address of the payment channel
paychAddr := chain.MustNewIDAddr(chain.MustIdFromAddress(receiverID) + 1)
paychAddr := chain.MustNewIDAddr(chain.MustIDFromAddress(receiverID) + 1)
createRet := td.ComputeInitActorExecReturn(sender, 0, 0, paychAddr)
preroot := td.GetStateRoot()
msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyExpect(
msg,
@ -239,7 +232,7 @@ func MessageTest_MessageApplicationEdgecases() error {
Signature: pcSig, // construct with invalid signature
},
}, chain.Nonce(1), chain.Value(big_spec.Zero()))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// message application fails due to invalid argument (signature).
td.ApplyFailure(
@ -248,13 +241,13 @@ func MessageTest_MessageApplicationEdgecases() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}
@ -267,15 +260,13 @@ func MessageTest_MessageApplicationEdgecases() error {
err = func(testname string) error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
preroot := td.GetStateRoot()
msg := td.MessageProducer.MarketComputeDataCommitment(alice, alice, nil, chain.Nonce(0))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// message application fails because ComputeDataCommitment isn't defined
// on the recipient actor
@ -285,13 +276,13 @@ func MessageTest_MessageApplicationEdgecases() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}
@ -304,8 +295,6 @@ func MessageTest_MessageApplicationEdgecases() error {
err = func(testname string) error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
preroot := td.GetStateRoot()
@ -314,7 +303,7 @@ func MessageTest_MessageApplicationEdgecases() error {
unknownA := chain.MustNewIDAddr(10000000)
msg := td.MessageProducer.Transfer(alice, unknownA, chain.Value(transferAmnt), chain.Nonce(0))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyFailure(
msg,
@ -323,7 +312,7 @@ func MessageTest_MessageApplicationEdgecases() error {
// Sending a message to non-existing actor address must produce an error.
unknownB := chain.MustNewActorAddr("1234")
msg = td.MessageProducer.Transfer(alice, unknownB, chain.Value(transferAmnt), chain.Nonce(1))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyFailure(
msg,
@ -331,13 +320,13 @@ func MessageTest_MessageApplicationEdgecases() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}

View File

@ -12,6 +12,7 @@ import (
"github.com/filecoin-project/oni/tvx/chain"
"github.com/filecoin-project/oni/tvx/drivers"
"github.com/filecoin-project/oni/tvx/schema"
)
func MessageTest_Paych() error {
@ -21,8 +22,6 @@ func MessageTest_Paych() error {
err := func(testname string) error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
// will create and send on payment channel
sender, senderID := td.NewAccountActor(drivers.SECP, initialBal)
@ -32,11 +31,11 @@ func MessageTest_Paych() error {
preroot := td.GetStateRoot()
// the _expected_ address of the payment channel
paychAddr := chain.MustNewIDAddr(chain.MustIdFromAddress(receiverID) + 1)
paychAddr := chain.MustNewIDAddr(chain.MustIDFromAddress(receiverID) + 1)
createRet := td.ComputeInitActorExecReturn(sender, 0, 0, paychAddr)
msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// init actor creates the payment channel
td.ApplyExpect(
@ -51,13 +50,13 @@ func MessageTest_Paych() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}
@ -70,8 +69,6 @@ func MessageTest_Paych() error {
err = func(testname string) error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
//const pcTimeLock = abi_spec.ChainEpoch(1)
const pcTimeLock = abi_spec.ChainEpoch(0)
const pcLane = uint64(123)
@ -91,11 +88,11 @@ func MessageTest_Paych() error {
preroot := td.GetStateRoot()
// the _expected_ address of the payment channel
paychAddr := chain.MustNewIDAddr(chain.MustIdFromAddress(receiverID) + 1)
paychAddr := chain.MustNewIDAddr(chain.MustIDFromAddress(receiverID) + 1)
createRet := td.ComputeInitActorExecReturn(sender, 0, 0, paychAddr)
msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyExpect(
msg,
chain.MustSerialize(&createRet))
@ -115,7 +112,7 @@ func MessageTest_Paych() error {
Signature: pcSig,
},
}, chain.Nonce(1), chain.Value(big_spec.Zero()))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyOk(msg)
var pcState paych_spec.State
@ -128,13 +125,13 @@ func MessageTest_Paych() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}
@ -147,18 +144,16 @@ func MessageTest_Paych() error {
err = func(testname string) error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
// create the payment channel
sender, _ := td.NewAccountActor(drivers.SECP, initialBal)
receiver, receiverID := td.NewAccountActor(drivers.SECP, initialBal)
paychAddr := chain.MustNewIDAddr(chain.MustIdFromAddress(receiverID) + 1)
paychAddr := chain.MustNewIDAddr(chain.MustIDFromAddress(receiverID) + 1)
initRet := td.ComputeInitActorExecReturn(sender, 0, 0, paychAddr)
preroot := td.GetStateRoot()
msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyExpect(
msg,
chain.MustSerialize(&initRet))
@ -183,21 +178,21 @@ func MessageTest_Paych() error {
},
}, chain.Nonce(1), chain.Value(big_spec.Zero()))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyOk(msg)
// settle the payment channel so it may be collected
msg = td.MessageProducer.PaychSettle(receiver, paychAddr, nil, chain.Value(big_spec.Zero()), chain.Nonce(0))
v.ApplyMessages = append(v.ApplyMessages, Message{Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
settleResult := td.ApplyOk(msg)
// advance the epoch so the funds may be redeemed.
td.ExeCtx.Epoch += paych_spec.SettleDelay
msg = td.MessageProducer.PaychCollect(receiver, paychAddr, nil, chain.Nonce(1), chain.Value(big_spec.Zero()))
v.ApplyMessages = append(v.ApplyMessages, Message{Epoch: &td.ExeCtx.Epoch, Bytes: chain.MustSerialize(msg)})
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Epoch: &td.ExeCtx.Epoch, Bytes: chain.MustSerialize(msg)})
collectResult := td.ApplyOk(msg)
@ -208,13 +203,13 @@ func MessageTest_Paych() error {
postroot := td.GetStateRoot()
v.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
v.Pre.StateTree.RootCID = preroot
v.Post.StateTree.RootCID = postroot
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
td.Vector.Pre.StateTree.RootCID = preroot
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&v); err != nil {
if err := enc.Encode(&td.Vector); err != nil {
return err
}