migrate actor creation suite. (#239)

This commit is contained in:
Raúl Kripalani 2020-08-16 13:40:02 +01:00 committed by GitHub
parent ad17dc227c
commit 6954e6cb0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 179 additions and 166 deletions

View File

@ -53,14 +53,17 @@ jobs:
name: "build tvx" name: "build tvx"
command: pushd tvx && go build . command: pushd tvx && go build .
- run: - run:
name: "run messages test vector suite (new api) - msg_application" name: "run messages test vector suite: msg_application"
command: pushd tvx/scripts/msg_application && go build . && ./msg_application | ../../tvx exec-lotus command: pushd tvx/scripts/msg_application && go build . && ./msg_application | ../../tvx exec-lotus
- run: - run:
name: "run messages test vector suite (new api) - nested send" name: "run messages test vector suite: nested send"
command: pushd tvx/scripts/nested && go build . && ./nested | ../../tvx exec-lotus command: pushd tvx/scripts/nested && go build . && ./nested | ../../tvx exec-lotus
- run: - run:
name: "run messages test vector suite (new api) - paych" name: "run messages test vector suite: paych"
command: pushd tvx/scripts/paych && go build . && ./paych | ../../tvx exec-lotus command: pushd tvx/scripts/paych && go build . && ./paych | ../../tvx exec-lotus
- run:
name: "run messages test vector suite: actor_creation"
command: pushd tvx/scripts/actor_creation && go build . && ./actor_creation | ../../tvx exec-lotus
soup-build-linux: soup-build-linux:
executor: linux executor: linux
steps: steps:

View File

@ -1,156 +0,0 @@
package main
import (
"os"
"github.com/hashicorp/go-multierror"
"github.com/urfave/cli/v2"
"github.com/filecoin-project/go-address"
abi_spec "github.com/filecoin-project/specs-actors/actors/abi"
big_spec "github.com/filecoin-project/specs-actors/actors/abi/big"
exitcode_spec "github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
"github.com/filecoin-project/oni/tvx/chain"
"github.com/filecoin-project/oni/tvx/drivers"
)
var suiteMessagesCmd = &cli.Command{
Name: "suite-messages",
Description: "generate test vectors from the messages test suite adapted from github.com/filecoin-project/chain-validation",
Action: suiteMessages,
}
func suiteMessages(c *cli.Context) error {
var err *multierror.Error
err = multierror.Append(MessageTest_AccountActorCreation())
err = multierror.Append(MessageTest_InitActorSequentialIDAddressCreate())
err = multierror.Append(MessageTest_MultiSigActor())
err = multierror.Append(MessageTest_ValueTransferSimple())
err = multierror.Append(MessageTest_ValueTransferAdvance())
return err.ErrorOrNil()
}
func MessageTest_AccountActorCreation() error {
testCases := []struct {
desc string
existingActorType address.Protocol
existingActorBal abi_spec.TokenAmount
newActorAddr address.Address
newActorInitBal abi_spec.TokenAmount
expExitCode exitcode_spec.ExitCode
}{
{
"success create SECP256K1 account actor",
address.SECP256K1,
abi_spec.NewTokenAmount(10_000_000_000),
chain.MustNewSECP256K1Addr("publickeyfoo"),
abi_spec.NewTokenAmount(10_000),
exitcode_spec.Ok,
},
{
"success create BLS account actor",
address.SECP256K1,
abi_spec.NewTokenAmount(10_000_000_000),
chain.MustNewBLSAddr(1),
abi_spec.NewTokenAmount(10_000),
exitcode_spec.Ok,
},
{
"fail create SECP256K1 account actor insufficient balance",
address.SECP256K1,
abi_spec.NewTokenAmount(9_999),
chain.MustNewSECP256K1Addr("publickeybar"),
abi_spec.NewTokenAmount(10_000),
exitcode_spec.SysErrSenderStateInvalid,
},
{
"fail create BLS account actor insufficient balance",
address.SECP256K1,
abi_spec.NewTokenAmount(9_999),
chain.MustNewBLSAddr(1),
abi_spec.NewTokenAmount(10_000),
exitcode_spec.SysErrSenderStateInvalid,
},
// TODO add edge case tests that have insufficient balance after gas fees
}
for _, tc := range testCases {
err := func() error {
td := drivers.NewTestDriver()
td.Vector.Meta.Desc = tc.desc
existingAccountAddr, _ := td.NewAccountActor(tc.existingActorType, tc.existingActorBal)
td.UpdatePreStateRoot()
msg := td.MessageProducer.Transfer(existingAccountAddr, tc.newActorAddr, chain.Value(tc.newActorInitBal), chain.Nonce(0))
result := td.ApplyFailure(
msg,
tc.expExitCode,
)
// new actor balance will only exist if message was applied successfully.
if tc.expExitCode.IsSuccess() {
td.AssertBalance(tc.newActorAddr, tc.newActorInitBal)
td.AssertBalance(existingAccountAddr, big_spec.Sub(big_spec.Sub(tc.existingActorBal, result.Receipt.GasUsed.Big()), tc.newActorInitBal))
}
td.MustSerialize(os.Stdout)
return nil
}()
if err != nil {
return err
}
}
return nil
}
func MessageTest_InitActorSequentialIDAddressCreate() error {
td := drivers.NewTestDriver()
var initialBal = abi_spec.NewTokenAmount(200_000_000_000)
var toSend = abi_spec.NewTokenAmount(10_000)
sender, _ := td.NewAccountActor(drivers.SECP, initialBal)
receiver, receiverID := td.NewAccountActor(drivers.SECP, initialBal)
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)
td.UpdatePreStateRoot()
msg1 := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0))
td.ApplyExpect(
msg1,
chain.MustSerialize(&firstInitRet),
)
msg2 := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(1))
td.ApplyExpect(
msg2,
chain.MustSerialize(&secondInitRet),
)
td.MustSerialize(os.Stdout)
return nil
}

View File

@ -137,5 +137,7 @@ func (a *Asserter) FailNow() {
} }
func (a *Asserter) Errorf(format string, args ...interface{}) { func (a *Asserter) Errorf(format string, args ...interface{}) {
fmt.Printf("%s: "+format, append([]interface{}{a.stage}, args...)) id := a.b.vector.Meta.ID
stage := a.stage
fmt.Printf("❌ id: %s, stage: %s:"+format, append([]interface{}{id, stage}, args...)...)
} }

View File

@ -15,8 +15,11 @@ const (
// CalculateDeduction returns the balance that shall be deducted from the // CalculateDeduction returns the balance that shall be deducted from the
// sender's account as a result of applying this message. // sender's account as a result of applying this message.
func CalculateDeduction(am *ApplicableMessage) big.Int { func CalculateDeduction(am *ApplicableMessage) big.Int {
m := am.Message if am.Result.GasUsed == 0 {
return big.Zero()
}
m := am.Message
minerReward := GetMinerReward(m.GasLimit, m.GasPremium) // goes to the miner minerReward := GetMinerReward(m.GasLimit, m.GasPremium) // goes to the miner
burn := CalculateBurn(m.GasLimit, am.Result.GasUsed) // vanishes burn := CalculateBurn(m.GasLimit, am.Result.GasUsed) // vanishes
deducted := big.Add(minerReward, burn) // sum of gas accrued deducted := big.Add(minerReward, burn) // sum of gas accrued

View File

@ -3,28 +3,23 @@ module github.com/filecoin-project/oni/tvx
go 1.14 go 1.14
require ( require (
github.com/filecoin-project/filecoin-ffi v0.30.4-0.20200716204036-cddc56607e1d
github.com/filecoin-project/go-address v0.0.3 github.com/filecoin-project/go-address v0.0.3
github.com/filecoin-project/go-bitfield v0.2.0 github.com/filecoin-project/go-bitfield v0.2.0
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f
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/hashicorp/go-multierror v1.1.0
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
github.com/ipfs/go-datastore v0.4.4 github.com/ipfs/go-datastore v0.4.4
github.com/ipfs/go-hamt-ipld v0.1.1 github.com/ipfs/go-hamt-ipld v0.1.1
github.com/ipfs/go-ipfs-blockstore v1.0.1
github.com/ipfs/go-ipfs-exchange-interface v0.0.1 github.com/ipfs/go-ipfs-exchange-interface v0.0.1
github.com/ipfs/go-ipfs-exchange-offline v0.0.1 github.com/ipfs/go-ipfs-exchange-offline v0.0.1
github.com/ipfs/go-ipld-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf github.com/ipfs/go-ipld-cbor v0.0.5-0.20200428170625-a0bd04d3cbdf
github.com/ipfs/go-ipld-format v0.2.0 github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-merkledag v0.3.2 github.com/ipfs/go-merkledag v0.3.2
github.com/ipld/go-car v0.1.1-0.20200526133713-1c7508d55aae github.com/ipld/go-car v0.1.1-0.20200526133713-1c7508d55aae
github.com/ipsn/go-secp256k1 v0.0.0-20180726113642-9d62b9f0bc52
github.com/libp2p/go-libp2p-core v0.6.1 github.com/libp2p/go-libp2p-core v0.6.1
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/multiformats/go-multiaddr v0.2.2 github.com/multiformats/go-multiaddr v0.2.2

View File

@ -0,0 +1,43 @@
package main
import (
. "github.com/filecoin-project/oni/tvx/builders"
"github.com/filecoin-project/specs-actors/actors/abi/big"
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
"github.com/filecoin-project/go-address"
)
func sequentialAddresses(v *Builder) {
v.Messages.SetDefaults(GasLimit(1_000_000_000), GasPremium(1), GasFeeCap(200))
initial := big.NewInt(1_000_000_000_000_000)
// Set up sender and receiver accounts.
var sender, receiver AddressHandle
v.Actors.AccountN(address.SECP256K1, initial, &sender, &receiver)
v.CommitPreconditions()
// Create 10 payment channels.
for i := uint64(0); i < 10; i++ {
v.Messages.Sugar().CreatePaychActor(sender.Robust, receiver.Robust, Value(big.NewInt(1000)), Nonce(i))
}
v.CommitApplies()
for i, am := range v.Messages.All() {
expectedActorAddr := AddressHandle{
ID: MustNewIDAddr(MustIDFromAddress(receiver.ID) + uint64(i) + 1),
Robust: sender.NextActorAddress(am.Message.Nonce, 0),
}
// Verify that the return contains the expected addresses.
var ret init_.ExecReturn
MustDeserialize(am.Result.Return, &ret)
v.Assert.Equal(expectedActorAddr.Robust, ret.RobustAddress)
v.Assert.Equal(expectedActorAddr.ID, ret.IDAddress)
}
v.Assert.EveryMessageSenderSatisfies(BalanceUpdated(big.Zero()))
v.Assert.EveryMessageSenderSatisfies(NonceUpdated())
}

View File

@ -0,0 +1,82 @@
package main
import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
. "github.com/filecoin-project/oni/tvx/builders"
"github.com/filecoin-project/oni/tvx/schema"
)
func main() {
g := NewGenerator()
g.MessageVectorGroup("addresses",
&MessageVectorGenItem{
Metadata: &schema.Metadata{
ID: "sequential-10",
Version: "v1",
Desc: "actor addresses are sequential",
},
Func: sequentialAddresses,
},
)
g.MessageVectorGroup("on_transfer",
&MessageVectorGenItem{
Metadata: &schema.Metadata{
ID: "ok-create-secp256k1",
Version: "v1",
},
Func: actorCreationOnTransfer(actorCreationOnTransferParams{
senderType: address.SECP256K1,
senderBal: abi.NewTokenAmount(1_000_000_000_000_000),
receiverAddr: MustNewSECP256K1Addr("publickeyfoo"),
amount: abi.NewTokenAmount(10_000),
exitCode: exitcode.Ok,
}),
},
&MessageVectorGenItem{
Metadata: &schema.Metadata{
ID: "ok-create-bls",
Version: "v1",
},
Func: actorCreationOnTransfer(actorCreationOnTransferParams{
senderType: address.SECP256K1,
senderBal: abi.NewTokenAmount(1_000_000_000_000_000),
receiverAddr: MustNewBLSAddr(1),
amount: abi.NewTokenAmount(10_000),
exitCode: exitcode.Ok,
}),
},
&MessageVectorGenItem{
Metadata: &schema.Metadata{
ID: "fail-secp256k1-insufficient-balance",
Version: "v1",
},
Func: actorCreationOnTransfer(actorCreationOnTransferParams{
senderType: address.SECP256K1,
senderBal: abi.NewTokenAmount(9_999),
receiverAddr: MustNewSECP256K1Addr("publickeyfoo"),
amount: abi.NewTokenAmount(10_000),
exitCode: exitcode.SysErrSenderStateInvalid,
}),
},
&MessageVectorGenItem{
Metadata: &schema.Metadata{
ID: "fail-bls-insufficient-balance",
Version: "v1",
},
Func: actorCreationOnTransfer(actorCreationOnTransferParams{
senderType: address.SECP256K1,
senderBal: abi.NewTokenAmount(9_999),
receiverAddr: MustNewBLSAddr(1),
amount: abi.NewTokenAmount(10_000),
exitCode: exitcode.SysErrSenderStateInvalid,
}),
},
)
g.Wait()
}

View File

@ -0,0 +1,41 @@
package main
import (
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi/big"
. "github.com/filecoin-project/oni/tvx/builders"
)
type actorCreationOnTransferParams struct {
senderType address.Protocol
senderBal abi.TokenAmount
receiverAddr address.Address
amount abi.TokenAmount
exitCode exitcode.ExitCode
}
func actorCreationOnTransfer(params actorCreationOnTransferParams) func(v *Builder) {
return func(v *Builder) {
v.Messages.SetDefaults(GasLimit(1_000_000_000), GasPremium(1), GasFeeCap(200))
// Set up sender account.
sender := v.Actors.Account(params.senderType, params.senderBal)
v.CommitPreconditions()
// Perform the transfer.
v.Messages.Sugar().Transfer(sender.ID, params.receiverAddr, Value(params.amount), Nonce(0))
v.CommitApplies()
v.Assert.EveryMessageResultSatisfies(ExitCode(params.exitCode))
v.Assert.EveryMessageSenderSatisfies(BalanceUpdated(big.Zero()))
if params.exitCode.IsSuccess() {
v.Assert.EveryMessageSenderSatisfies(NonceUpdated())
v.Assert.BalanceEq(params.receiverAddr, params.amount)
}
}
}