lotus/conformance/driver.go
Raúl Kripalani 322b33197c introduce interoperable vector-based conformance testing.
This commit introduces a new package `conformance` containing:

 1. the test driver to exercise Lotus against interoperable
    test vectors, and
 2. the test runner, which integrates go test with the test vector
    corpus hosted at https://github.com/filecoin-project/conformance-vectors.

The corpus is mounted via a git submodule.

Right now, only message-class test vectors are supported. In the
next week, this support will be extended to tipset-class, chain-class,
and block sequence-class vectors.
2020-08-16 00:15:52 +01:00

60 lines
1.6 KiB
Go

package conformance
import (
"context"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/puppet"
"github.com/ipfs/go-cid"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/lib/blockstore"
"github.com/filecoin-project/sector-storage/ffiwrapper"
)
var (
// BaseFee to use in the VM.
// TODO make parametrisable through vector.
BaseFee = abi.NewTokenAmount(100)
)
type Driver struct {
ctx context.Context
}
func NewDriver(ctx context.Context) *Driver {
return &Driver{ctx: ctx}
}
// ExecuteMessage executes a conformance test vector message in a temporary VM.
func (d *Driver) ExecuteMessage(msg *types.Message, preroot cid.Cid, bs blockstore.Blockstore, epoch abi.ChainEpoch) (*vm.ApplyRet, cid.Cid, error) {
vmOpts := &vm.VMOpts{
StateBase: preroot,
Epoch: epoch,
Rand: &testRand{}, // TODO always succeeds; need more flexibility.
Bstore: bs,
Syscalls: mkFakedSigSyscalls(vm.Syscalls(ffiwrapper.ProofVerifier)), // TODO always succeeds; need more flexibility.
CircSupplyCalc: nil,
BaseFee: BaseFee,
}
lvm, err := vm.NewVM(vmOpts)
if err != nil {
return nil, cid.Undef, err
}
// add support for the puppet actor.
invoker := vm.NewInvoker()
invoker.Register(puppet.PuppetActorCodeID, puppet.Actor{}, puppet.State{})
lvm.SetInvoker(invoker)
ret, err := lvm.ApplyMessage(d.ctx, msg)
if err != nil {
return nil, cid.Undef, err
}
root, err := lvm.Flush(d.ctx)
return ret, root, err
}