input from stdin functionality for exec-lotus ; initial test suites in ci (#196)

This commit is contained in:
Anton Evangelatov 2020-08-05 20:59:57 +02:00 committed by GitHub
parent f97c9e08c0
commit 9c8ced1fc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 41 deletions

View File

@ -41,16 +41,24 @@ workflows:
version: 2
main:
jobs:
- build-linux
- tvx-build-test-linux
- soup-build-linux
jobs:
build-linux:
tvx-build-test-linux:
executor: linux
steps:
- setup
- run:
name: "build tvx"
command: pushd tvx && go build .
- run:
name: "run messages test vector suite"
command: pushd tvx && ./tvx suite-messages | ./tvx exec-lotus
soup-build-linux:
executor: linux
steps:
- setup
- run:
name: "build lotus-soup"
command: pushd lotus-soup && go build -tags=testground .
- run:
name: "build tvx"
command: pushd tvx && go build .

View File

@ -6,11 +6,10 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"github.com/davecgh/go-spew/spew"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/lib/blockstore"
"github.com/ipld/go-car"
"github.com/urfave/cli/v2"
@ -29,7 +28,6 @@ var execLotusCmd = &cli.Command{
&cli.StringFlag{
Name: "file",
Usage: "input file",
Required: true,
Destination: &execLotusFlags.file,
},
},
@ -37,10 +35,8 @@ var execLotusCmd = &cli.Command{
}
func runExecLotus(_ *cli.Context) error {
if execLotusFlags.file == "" {
return fmt.Errorf("test vector file cannot be empty")
}
switch {
case execLotusFlags.file != "":
file, err := os.Open(execLotusFlags.file)
if err != nil {
return fmt.Errorf("failed to open test vector: %w", err)
@ -55,12 +51,36 @@ func runExecLotus(_ *cli.Context) error {
return fmt.Errorf("failed to decode test vector: %w", err)
}
return executeTestVector(tv)
default:
dec := json.NewDecoder(os.Stdin)
for {
var tv TestVector
err := dec.Decode(&tv)
if err == io.EOF {
return nil
}
if err != nil {
return err
}
err = executeTestVector(tv)
if err != nil {
return err
}
}
}
}
func executeTestVector(tv TestVector) error {
fmt.Println("executing test vector")
switch tv.Class {
case "message":
var (
ctx = context.Background()
epoch = tv.Pre.Epoch
preroot = tv.Pre.StateTree.RootCID
root = tv.Pre.StateTree.RootCID
)
bs := blockstore.NewTemporary()
@ -89,12 +109,14 @@ func runExecLotus(_ *cli.Context) error {
}
fmt.Printf("executing message %v\n", i)
var applyRet *vm.ApplyRet
applyRet, preroot, err = driver.ExecuteMessage(msg, preroot, bs, epoch)
_, root, err = driver.ExecuteMessage(msg, root, bs, epoch)
if err != nil {
return err
}
spew.Dump(applyRet)
}
if root != tv.Post.StateTree.RootCID {
return fmt.Errorf("wrong post root cid; expected %v , but got %v", tv.Post.StateTree.RootCID, root)
}
return nil

View File

@ -3,7 +3,6 @@ module github.com/filecoin-project/oni/tvx
go 1.14
require (
github.com/davecgh/go-spew v1.1.1
github.com/filecoin-project/filecoin-ffi v0.30.4-0.20200716204036-cddc56607e1d
github.com/filecoin-project/go-address v0.0.2-0.20200504173055-8b6f2fb2b3ef
github.com/filecoin-project/go-bitfield v0.1.2

View File

@ -22,9 +22,10 @@ func MessageTest_MessageApplicationEdgecases() error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
preroot := td.GetStateRoot()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(1), chain.GasLimit(8))
v.ApplyMessages = append(v.ApplyMessages, chain.MustSerialize(msg))
@ -51,20 +52,24 @@ func MessageTest_MessageApplicationEdgecases() error {
}
err = func(testname string) error {
//TODO: this test is broken, fix later
return nil
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
preroot := td.GetStateRoot()
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))
// Expect Message application to fail due to lack of gas
td.ApplyFailure(
td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1)),
msg,
exitcode_spec.SysErrOutOfGas)
// Expect Message application to fail due to lack of gas when sender is unknown
unknown := chain.MustNewIDAddr(10000000)
msg := td.MessageProducer.Transfer(unknown, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1))
msg = td.MessageProducer.Transfer(unknown, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1))
v.ApplyMessages = append(v.ApplyMessages, chain.MustSerialize(msg))
td.ApplyFailure(
@ -93,9 +98,10 @@ func MessageTest_MessageApplicationEdgecases() error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
preroot := td.GetStateRoot()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
preroot := td.GetStateRoot()
aliceNonce := uint64(0)
aliceNonceF := func() uint64 {
defer func() { aliceNonce++ }()
@ -142,13 +148,16 @@ func MessageTest_MessageApplicationEdgecases() error {
}
err = func(testname string) error {
//TODO: this test is broken, fix me
return nil
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
preroot := td.GetStateRoot()
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, chain.MustSerialize(msg))
@ -179,7 +188,7 @@ func MessageTest_MessageApplicationEdgecases() error {
}
return nil
}("invalid actor CallSeqNum")
}("invalid actor nonce")
if err != nil {
return err
}
@ -188,7 +197,6 @@ func MessageTest_MessageApplicationEdgecases() error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
preroot := td.GetStateRoot()
const pcTimeLock = abi_spec.ChainEpoch(10)
const pcLane = uint64(123)
@ -210,6 +218,8 @@ func MessageTest_MessageApplicationEdgecases() error {
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, chain.MustSerialize(msg))
@ -261,11 +271,13 @@ func MessageTest_MessageApplicationEdgecases() error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
preroot := td.GetStateRoot()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
preroot := td.GetStateRoot()
msg := td.MessageProducer.MarketComputeDataCommitment(alice, alice, nil, chain.Nonce(0))
v.ApplyMessages = append(v.ApplyMessages, chain.MustSerialize(msg))
// message application fails because ComputeDataCommitment isn't defined
@ -296,10 +308,11 @@ func MessageTest_MessageApplicationEdgecases() error {
td := drivers.NewTestDriver()
v := newEmptyMessageVector()
preroot := td.GetStateRoot()
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
preroot := td.GetStateRoot()
// Sending a message to non-existent ID address must produce an error.
unknownA := chain.MustNewIDAddr(10000000)
msg := td.MessageProducer.Transfer(alice, unknownA, chain.Value(transferAmnt), chain.Nonce(0))