flip to test-vectors schema
This commit is contained in:
parent
6cff57ab43
commit
20a0f7ac68
@ -14,7 +14,7 @@ import (
|
|||||||
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
|
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
|
||||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||||
|
|
||||||
"github.com/filecoin-project/oni/tvx/schema"
|
"github.com/filecoin-project/test-vectors/schema"
|
||||||
"github.com/filecoin-project/oni/tvx/state"
|
"github.com/filecoin-project/oni/tvx/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/chain/vm"
|
"github.com/filecoin-project/lotus/chain/vm"
|
||||||
"github.com/filecoin-project/lotus/lib/blockstore"
|
"github.com/filecoin-project/lotus/lib/blockstore"
|
||||||
@ -16,7 +17,7 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/filecoin-project/oni/tvx/lotus"
|
"github.com/filecoin-project/oni/tvx/lotus"
|
||||||
"github.com/filecoin-project/oni/tvx/schema"
|
"github.com/filecoin-project/test-vectors/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
var execLotusFlags struct {
|
var execLotusFlags struct {
|
||||||
@ -117,12 +118,12 @@ func executeTestVector(tv schema.TestVector) error {
|
|||||||
|
|
||||||
fmt.Printf("executing message %v\n", i)
|
fmt.Printf("executing message %v\n", i)
|
||||||
var ret *vm.ApplyRet
|
var ret *vm.ApplyRet
|
||||||
ret, root, err = driver.ExecuteMessage(msg, root, bs, epoch)
|
ret, root, err = driver.ExecuteMessage(msg, root, bs, abi.ChainEpoch(epoch))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if expected, actual := tv.Post.Receipts[i].ExitCode, ret.ExitCode; expected != actual {
|
if expected, actual := tv.Post.Receipts[i].ExitCode, ret.ExitCode; expected != int64(actual) {
|
||||||
return fmt.Errorf("exit code of msg %d did not match; expected: %s, got: %s", i, expected, actual)
|
return fmt.Errorf("exit code of msg %d did not match; expected: %s, got: %s", i, expected, actual)
|
||||||
}
|
}
|
||||||
if expected, actual := tv.Post.Receipts[i].GasUsed, ret.GasUsed; expected != actual {
|
if expected, actual := tv.Post.Receipts[i].GasUsed, ret.GasUsed; expected != actual {
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
"github.com/filecoin-project/oni/tvx/lotus"
|
"github.com/filecoin-project/oni/tvx/lotus"
|
||||||
"github.com/filecoin-project/oni/tvx/schema"
|
"github.com/filecoin-project/test-vectors/schema"
|
||||||
"github.com/filecoin-project/oni/tvx/state"
|
"github.com/filecoin-project/oni/tvx/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -204,18 +204,18 @@ func runExtractMsg(c *cli.Context) error {
|
|||||||
// Write out the test vector.
|
// Write out the test vector.
|
||||||
vector := schema.TestVector{
|
vector := schema.TestVector{
|
||||||
Class: schema.ClassMessage,
|
Class: schema.ClassMessage,
|
||||||
Selector: "",
|
Selector: schema.Selector(map[string]string{}),
|
||||||
Meta: &schema.Metadata{
|
Meta: &schema.Metadata{
|
||||||
ID: "TK",
|
ID: "TK",
|
||||||
Version: "TK",
|
Version: "TK",
|
||||||
Gen: schema.GenerationData{
|
Gen: []schema.GenerationData{schema.GenerationData{
|
||||||
Source: "TK",
|
Source: "TK",
|
||||||
Version: version.String(),
|
Version: version.String(),
|
||||||
},
|
}},
|
||||||
},
|
},
|
||||||
CAR: out.Bytes(),
|
CAR: out.Bytes(),
|
||||||
Pre: &schema.Preconditions{
|
Pre: &schema.Preconditions{
|
||||||
Epoch: execTs.Height(),
|
Epoch: int64(execTs.Height()),
|
||||||
StateTree: &schema.StateTree{
|
StateTree: &schema.StateTree{
|
||||||
RootCID: preroot,
|
RootCID: preroot,
|
||||||
},
|
},
|
||||||
|
@ -9,6 +9,7 @@ require (
|
|||||||
github.com/filecoin-project/lotus v0.4.3-0.20200814191300-4a0171d26aa5
|
github.com/filecoin-project/lotus v0.4.3-0.20200814191300-4a0171d26aa5
|
||||||
github.com/filecoin-project/sector-storage v0.0.0-20200810171746-eac70842d8e0
|
github.com/filecoin-project/sector-storage v0.0.0-20200810171746-eac70842d8e0
|
||||||
github.com/filecoin-project/specs-actors v0.9.2
|
github.com/filecoin-project/specs-actors v0.9.2
|
||||||
|
github.com/filecoin-project/test-vectors/schema v0.0.1
|
||||||
github.com/ipfs/go-block-format v0.0.2
|
github.com/ipfs/go-block-format v0.0.2
|
||||||
github.com/ipfs/go-blockservice v0.1.4-0.20200624145336-a978cec6e834
|
github.com/ipfs/go-blockservice v0.1.4-0.20200624145336-a978cec6e834
|
||||||
github.com/ipfs/go-cid v0.0.7
|
github.com/ipfs/go-cid v0.0.7
|
||||||
|
@ -260,6 +260,9 @@ github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea/g
|
|||||||
github.com/filecoin-project/specs-storage v0.1.1-0.20200730063404-f7db367e9401 h1:jLzN1hwO5WpKPu8ASbW8fs1FUCsOWNvoBXzQhv+8/E8=
|
github.com/filecoin-project/specs-storage v0.1.1-0.20200730063404-f7db367e9401 h1:jLzN1hwO5WpKPu8ASbW8fs1FUCsOWNvoBXzQhv+8/E8=
|
||||||
github.com/filecoin-project/specs-storage v0.1.1-0.20200730063404-f7db367e9401/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k=
|
github.com/filecoin-project/specs-storage v0.1.1-0.20200730063404-f7db367e9401/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k=
|
||||||
github.com/filecoin-project/storage-fsm v0.0.0-20200805013058-9d9ea4e6331f/go.mod h1:1CGbd11KkHuyWPT+xwwCol1zl/jnlpiKD2L4fzKxaiI=
|
github.com/filecoin-project/storage-fsm v0.0.0-20200805013058-9d9ea4e6331f/go.mod h1:1CGbd11KkHuyWPT+xwwCol1zl/jnlpiKD2L4fzKxaiI=
|
||||||
|
github.com/filecoin-project/test-vectors v0.0.0-20200914135529-71c6d51eed96 h1:VL/ECJieBOVlxHXp4W42UEPC6/OHg9us3Mfx/8AkCEE=
|
||||||
|
github.com/filecoin-project/test-vectors/schema v0.0.1 h1:5fNF76nl4qolEvcIsjc0kUADlTMVHO73tW4kXXPnsus=
|
||||||
|
github.com/filecoin-project/test-vectors/schema v0.0.1/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
|
||||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||||
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
|
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
|
||||||
github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY=
|
github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY=
|
||||||
|
@ -1,132 +0,0 @@
|
|||||||
package schema
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/base64"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
|
||||||
"github.com/ipfs/go-cid"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Class represents the type of test this instance is.
|
|
||||||
type Class string
|
|
||||||
|
|
||||||
var (
|
|
||||||
// ClassMessage tests the VM transition over a single message
|
|
||||||
ClassMessage Class = "message"
|
|
||||||
// ClassBlock tests the VM transition over a block of messages
|
|
||||||
ClassBlock Class = "block"
|
|
||||||
// ClassTipset tests the VM transition on a tipset update
|
|
||||||
ClassTipset Class = "tipset"
|
|
||||||
// ClassChain tests the VM transition across a chain segment
|
|
||||||
ClassChain Class = "chain"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Selector provides a filter to indicate what implementations this test is relevant for
|
|
||||||
type Selector string
|
|
||||||
|
|
||||||
// Metadata provides information on the generation of this test case
|
|
||||||
type Metadata struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
Version string `json:"version,omitempty"`
|
|
||||||
Desc string `json:"description,omitempty"`
|
|
||||||
Comment string `json:"comment,omitempty"`
|
|
||||||
Gen GenerationData `json:"gen"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerationData tags the source of this test case
|
|
||||||
type GenerationData struct {
|
|
||||||
Source string `json:"source,omitempty"`
|
|
||||||
Version string `json:"version,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// StateTree represents a state tree within preconditions and postconditions.
|
|
||||||
type StateTree struct {
|
|
||||||
RootCID cid.Cid `json:"root_cid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Base64EncodedBytes is a base64-encoded binary value.
|
|
||||||
type Base64EncodedBytes []byte
|
|
||||||
|
|
||||||
// Preconditions contain a representation of VM state at the beginning of the test
|
|
||||||
type Preconditions struct {
|
|
||||||
Epoch abi.ChainEpoch `json:"epoch"`
|
|
||||||
StateTree *StateTree `json:"state_tree"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Receipt represents a receipt to match against.
|
|
||||||
type Receipt struct {
|
|
||||||
ExitCode exitcode.ExitCode `json:"exit_code"`
|
|
||||||
ReturnValue Base64EncodedBytes `json:"return"`
|
|
||||||
GasUsed int64 `json:"gas_used"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Postconditions contain a representation of VM state at th end of the test
|
|
||||||
type Postconditions struct {
|
|
||||||
StateTree *StateTree `json:"state_tree"`
|
|
||||||
Receipts []*Receipt `json:"receipts"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON implements json.Marshal for Base64EncodedBytes
|
|
||||||
func (beb Base64EncodedBytes) MarshalJSON() ([]byte, error) {
|
|
||||||
return json.Marshal(base64.StdEncoding.EncodeToString(beb))
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON implements json.Unmarshal for Base64EncodedBytes
|
|
||||||
func (beb *Base64EncodedBytes) UnmarshalJSON(v []byte) error {
|
|
||||||
var s string
|
|
||||||
if err := json.Unmarshal(v, &s); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
bytes, err := base64.StdEncoding.DecodeString(s)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*beb = bytes
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestVector is a single test case
|
|
||||||
type TestVector struct {
|
|
||||||
Class `json:"class"`
|
|
||||||
Selector `json:"selector,omitempty"`
|
|
||||||
Meta *Metadata `json:"_meta"`
|
|
||||||
|
|
||||||
// CAR binary data to be loaded into the test environment, usually a CAR
|
|
||||||
// containing multiple state trees, addressed by root CID from the relevant
|
|
||||||
// objects.
|
|
||||||
CAR Base64EncodedBytes `json:"car"`
|
|
||||||
|
|
||||||
Pre *Preconditions `json:"preconditions"`
|
|
||||||
ApplyMessages []Message `json:"apply_messages"`
|
|
||||||
Post *Postconditions `json:"postconditions"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Message struct {
|
|
||||||
Bytes Base64EncodedBytes `json:"bytes"`
|
|
||||||
Epoch *abi.ChainEpoch `json:"epoch,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate validates this test vector against the JSON schema, and applies
|
|
||||||
// further validation rules that cannot be enforced through JSON Schema.
|
|
||||||
func (tv TestVector) Validate() error {
|
|
||||||
// TODO validate against JSON Schema.
|
|
||||||
if tv.Class == ClassMessage {
|
|
||||||
if len(tv.Post.Receipts) != len(tv.ApplyMessages) {
|
|
||||||
return fmt.Errorf("length of postcondition receipts must match length of messages to apply")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MustMarshalJSON encodes the test vector to JSON and panics if it errors.
|
|
||||||
func (tv TestVector) MustMarshalJSON() []byte {
|
|
||||||
b, err := json.Marshal(&tv)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return b
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user