2020-08-15 22:57:27 +00:00
|
|
|
package conformance
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-08-26 20:39:44 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/lotus/chain/vm"
|
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
|
|
|
"github.com/filecoin-project/lotus/lib/blockstore"
|
|
|
|
|
2020-08-15 22:57:27 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/puppet"
|
2020-08-19 13:31:34 +00:00
|
|
|
|
2020-08-21 10:51:50 +00:00
|
|
|
"github.com/filecoin-project/test-vectors/chaos"
|
2020-08-26 20:39:44 +00:00
|
|
|
"github.com/filecoin-project/test-vectors/schema"
|
2020-08-21 10:51:50 +00:00
|
|
|
|
2020-08-26 20:39:44 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-08-15 22:57:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// BaseFee to use in the VM.
|
|
|
|
// TODO make parametrisable through vector.
|
|
|
|
BaseFee = abi.NewTokenAmount(100)
|
|
|
|
)
|
|
|
|
|
|
|
|
type Driver struct {
|
2020-08-19 17:10:56 +00:00
|
|
|
ctx context.Context
|
|
|
|
vector *schema.TestVector
|
2020-08-15 22:57:27 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 17:10:56 +00:00
|
|
|
func NewDriver(ctx context.Context, vector *schema.TestVector) *Driver {
|
|
|
|
return &Driver{ctx: ctx, vector: vector}
|
2020-08-15 22:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
invoker := vm.NewInvoker()
|
2020-08-21 10:51:50 +00:00
|
|
|
|
|
|
|
// add support for the puppet and chaos actors.
|
2020-08-26 10:45:34 +00:00
|
|
|
if puppetOn, ok := d.vector.Selector["puppet_actor"]; ok && puppetOn == "true" {
|
2020-08-21 10:51:50 +00:00
|
|
|
invoker.Register(puppet.PuppetActorCodeID, puppet.Actor{}, puppet.State{})
|
|
|
|
}
|
2020-08-26 10:45:34 +00:00
|
|
|
if chaosOn, ok := d.vector.Selector["chaos_actor"]; ok && chaosOn == "true" {
|
2020-08-19 17:10:56 +00:00
|
|
|
invoker.Register(chaos.ChaosActorCodeCID, chaos.Actor{}, chaos.State{})
|
|
|
|
}
|
|
|
|
|
2020-08-15 22:57:27 +00:00
|
|
|
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
|
|
|
|
}
|