2020-08-05 17:40:09 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-08-07 13:09:10 +00:00
|
|
|
"fmt"
|
2020-08-05 17:40:09 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
abi_spec "github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
big_spec "github.com/filecoin-project/specs-actors/actors/abi/big"
|
|
|
|
paych_spec "github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
|
|
|
crypto_spec "github.com/filecoin-project/specs-actors/actors/crypto"
|
|
|
|
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"
|
2020-08-07 12:47:16 +00:00
|
|
|
"github.com/filecoin-project/oni/tvx/schema"
|
2020-08-05 17:40:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func MessageTest_MessageApplicationEdgecases() error {
|
|
|
|
var aliceBal = abi_spec.NewTokenAmount(1_000_000_000_000)
|
|
|
|
var transferAmnt = abi_spec.NewTokenAmount(10)
|
|
|
|
|
|
|
|
err := func(testname string) error {
|
|
|
|
td := drivers.NewTestDriver()
|
|
|
|
|
2020-08-05 18:59:57 +00:00
|
|
|
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
|
|
|
|
|
2020-08-05 17:40:09 +00:00
|
|
|
preroot := td.GetStateRoot()
|
|
|
|
|
|
|
|
msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(1), chain.GasLimit(8))
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
td.ApplyFailure(
|
|
|
|
msg,
|
|
|
|
exitcode_spec.SysErrOutOfGas)
|
|
|
|
|
|
|
|
postroot := td.GetStateRoot()
|
|
|
|
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
|
|
|
|
td.Vector.Pre.StateTree.RootCID = preroot
|
|
|
|
td.Vector.Post.StateTree.RootCID = postroot
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// encode and output
|
2020-08-07 13:09:10 +00:00
|
|
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}("fail to cover gas cost for message receipt on chain")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = func(testname string) error {
|
|
|
|
td := drivers.NewTestDriver()
|
|
|
|
|
|
|
|
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
|
2020-08-05 18:59:57 +00:00
|
|
|
|
|
|
|
preroot := td.GetStateRoot()
|
|
|
|
msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1))
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-06 16:57:15 +00:00
|
|
|
|
2020-08-05 17:40:09 +00:00
|
|
|
// Expect Message application to fail due to lack of gas
|
|
|
|
td.ApplyFailure(
|
2020-08-05 18:59:57 +00:00
|
|
|
msg,
|
2020-08-05 17:40:09 +00:00
|
|
|
exitcode_spec.SysErrOutOfGas)
|
|
|
|
|
|
|
|
unknown := chain.MustNewIDAddr(10000000)
|
2020-08-05 18:59:57 +00:00
|
|
|
msg = td.MessageProducer.Transfer(unknown, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1))
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
2020-08-06 16:57:15 +00:00
|
|
|
// Expect Message application to fail due to lack of gas when sender is unknown
|
2020-08-05 17:40:09 +00:00
|
|
|
td.ApplyFailure(
|
|
|
|
msg,
|
|
|
|
exitcode_spec.SysErrOutOfGas)
|
|
|
|
|
|
|
|
postroot := td.GetStateRoot()
|
|
|
|
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
|
|
|
|
td.Vector.Pre.StateTree.RootCID = preroot
|
|
|
|
td.Vector.Post.StateTree.RootCID = postroot
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// encode and output
|
2020-08-07 13:09:10 +00:00
|
|
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}("not enough gas to pay message on-chain-size cost")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = func(testname string) error {
|
|
|
|
td := drivers.NewTestDriver()
|
|
|
|
|
|
|
|
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
|
2020-08-05 18:59:57 +00:00
|
|
|
preroot := td.GetStateRoot()
|
|
|
|
|
2020-08-05 17:40:09 +00:00
|
|
|
aliceNonce := uint64(0)
|
|
|
|
aliceNonceF := func() uint64 {
|
|
|
|
defer func() { aliceNonce++ }()
|
|
|
|
return aliceNonce
|
|
|
|
}
|
|
|
|
newAccountA := chain.MustNewSECP256K1Addr("1")
|
|
|
|
|
|
|
|
msg := td.MessageProducer.Transfer(alice, newAccountA, chain.Value(transferAmnt), chain.Nonce(aliceNonceF()))
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// get the "true" gas cost of applying the message
|
|
|
|
result := td.ApplyOk(msg)
|
|
|
|
|
|
|
|
// decrease the gas cost by `gasStep` for each apply and ensure `SysErrOutOfGas` is always returned.
|
|
|
|
trueGas := int64(result.GasUsed())
|
|
|
|
gasStep := int64(trueGas / 100)
|
|
|
|
newAccountB := chain.MustNewSECP256K1Addr("2")
|
|
|
|
for tryGas := trueGas - gasStep; tryGas > 0; tryGas -= gasStep {
|
|
|
|
msg := td.MessageProducer.Transfer(alice, newAccountB, chain.Value(transferAmnt), chain.Nonce(aliceNonceF()), chain.GasPrice(1), chain.GasLimit(tryGas))
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
td.ApplyFailure(
|
|
|
|
msg,
|
|
|
|
exitcode_spec.SysErrOutOfGas,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
postroot := td.GetStateRoot()
|
|
|
|
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
|
|
|
|
td.Vector.Pre.StateTree.RootCID = preroot
|
|
|
|
td.Vector.Post.StateTree.RootCID = postroot
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// encode and output
|
2020-08-07 13:09:10 +00:00
|
|
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}("fail not enough gas to cover account actor creation")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = func(testname string) error {
|
|
|
|
td := drivers.NewTestDriver()
|
|
|
|
|
|
|
|
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
|
|
|
|
|
2020-08-05 18:59:57 +00:00
|
|
|
preroot := td.GetStateRoot()
|
|
|
|
|
2020-08-05 17:40:09 +00:00
|
|
|
msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(1))
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// Expect Message application to fail due to callseqnum being invalid: 1 instead of 0
|
|
|
|
td.ApplyFailure(
|
|
|
|
msg,
|
|
|
|
exitcode_spec.SysErrSenderStateInvalid)
|
|
|
|
|
|
|
|
unknown := chain.MustNewIDAddr(10000000)
|
|
|
|
msg = td.MessageProducer.Transfer(unknown, alice, chain.Value(transferAmnt), chain.Nonce(1))
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// Expect message application to fail due to unknow actor when call seq num is also incorrect
|
|
|
|
td.ApplyFailure(
|
|
|
|
msg,
|
|
|
|
exitcode_spec.SysErrSenderInvalid)
|
|
|
|
|
|
|
|
postroot := td.GetStateRoot()
|
|
|
|
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
|
|
|
|
td.Vector.Pre.StateTree.RootCID = preroot
|
|
|
|
td.Vector.Post.StateTree.RootCID = postroot
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// encode and output
|
2020-08-07 13:09:10 +00:00
|
|
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
return nil
|
2020-08-05 18:59:57 +00:00
|
|
|
}("invalid actor nonce")
|
2020-08-05 17:40:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = func(testname string) error {
|
|
|
|
td := drivers.NewTestDriver()
|
|
|
|
|
|
|
|
const pcTimeLock = abi_spec.ChainEpoch(10)
|
|
|
|
const pcLane = uint64(123)
|
|
|
|
const pcNonce = uint64(1)
|
|
|
|
var pcAmount = big_spec.NewInt(10)
|
|
|
|
var initialBal = abi_spec.NewTokenAmount(200_000_000_000)
|
|
|
|
var toSend = abi_spec.NewTokenAmount(10_000)
|
|
|
|
var pcSig = &crypto_spec.Signature{
|
|
|
|
Type: crypto_spec.SigTypeBLS,
|
|
|
|
Data: []byte("Grrr im an invalid signature, I cause panics in the payment channel actor"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// will create and send on payment channel
|
|
|
|
sender, _ := td.NewAccountActor(drivers.SECP, initialBal)
|
|
|
|
// will be receiver on paych
|
|
|
|
receiver, receiverID := td.NewAccountActor(drivers.SECP, initialBal)
|
|
|
|
|
|
|
|
// the _expected_ address of the payment channel
|
2020-08-07 12:47:16 +00:00
|
|
|
paychAddr := chain.MustNewIDAddr(chain.MustIDFromAddress(receiverID) + 1)
|
2020-08-05 17:40:09 +00:00
|
|
|
createRet := td.ComputeInitActorExecReturn(sender, 0, 0, paychAddr)
|
|
|
|
|
2020-08-05 18:59:57 +00:00
|
|
|
preroot := td.GetStateRoot()
|
|
|
|
|
2020-08-05 17:40:09 +00:00
|
|
|
msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0))
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
td.ApplyExpect(
|
|
|
|
msg,
|
|
|
|
chain.MustSerialize(&createRet))
|
|
|
|
|
|
|
|
msg = td.MessageProducer.PaychUpdateChannelState(sender, paychAddr, &paych_spec.UpdateChannelStateParams{
|
|
|
|
Sv: paych_spec.SignedVoucher{
|
|
|
|
ChannelAddr: paychAddr,
|
|
|
|
TimeLockMin: pcTimeLock,
|
|
|
|
TimeLockMax: pcTimeLock,
|
|
|
|
SecretPreimage: nil,
|
|
|
|
Extra: nil,
|
|
|
|
Lane: pcLane,
|
|
|
|
Nonce: pcNonce,
|
|
|
|
Amount: pcAmount,
|
|
|
|
MinSettleHeight: 0,
|
|
|
|
Merges: nil,
|
|
|
|
Signature: pcSig, // construct with invalid signature
|
|
|
|
},
|
|
|
|
}, chain.Nonce(1), chain.Value(big_spec.Zero()))
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// message application fails due to invalid argument (signature).
|
|
|
|
td.ApplyFailure(
|
|
|
|
msg,
|
|
|
|
exitcode_spec.ErrIllegalArgument)
|
|
|
|
|
|
|
|
postroot := td.GetStateRoot()
|
|
|
|
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
|
|
|
|
td.Vector.Pre.StateTree.RootCID = preroot
|
|
|
|
td.Vector.Post.StateTree.RootCID = postroot
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// encode and output
|
2020-08-07 13:09:10 +00:00
|
|
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}("abort during actor execution")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = func(testname string) error {
|
|
|
|
td := drivers.NewTestDriver()
|
|
|
|
|
|
|
|
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
|
|
|
|
|
2020-08-05 18:59:57 +00:00
|
|
|
preroot := td.GetStateRoot()
|
|
|
|
|
2020-08-05 17:40:09 +00:00
|
|
|
msg := td.MessageProducer.MarketComputeDataCommitment(alice, alice, nil, chain.Nonce(0))
|
2020-08-05 18:59:57 +00:00
|
|
|
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// message application fails because ComputeDataCommitment isn't defined
|
|
|
|
// on the recipient actor
|
|
|
|
td.ApplyFailure(
|
|
|
|
msg,
|
|
|
|
exitcode_spec.SysErrInvalidMethod)
|
|
|
|
|
|
|
|
postroot := td.GetStateRoot()
|
|
|
|
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
|
|
|
|
td.Vector.Pre.StateTree.RootCID = preroot
|
|
|
|
td.Vector.Post.StateTree.RootCID = postroot
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// encode and output
|
2020-08-07 13:09:10 +00:00
|
|
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}("invalid method for receiver")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = func(testname string) error {
|
|
|
|
td := drivers.NewTestDriver()
|
|
|
|
|
|
|
|
alice, _ := td.NewAccountActor(drivers.SECP, aliceBal)
|
|
|
|
|
2020-08-05 18:59:57 +00:00
|
|
|
preroot := td.GetStateRoot()
|
|
|
|
|
2020-08-05 17:40:09 +00:00
|
|
|
// 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))
|
|
|
|
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
td.ApplyFailure(
|
|
|
|
msg,
|
|
|
|
exitcode_spec.SysErrInvalidReceiver)
|
|
|
|
|
|
|
|
// Sending a message to non-existing actor address must produce an error.
|
|
|
|
unknownB := chain.MustNewActorAddr("1234")
|
|
|
|
msg = td.MessageProducer.Transfer(alice, unknownB, chain.Value(transferAmnt), chain.Nonce(1))
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
td.ApplyFailure(
|
|
|
|
msg,
|
|
|
|
exitcode_spec.SysErrInvalidReceiver)
|
|
|
|
|
|
|
|
postroot := td.GetStateRoot()
|
|
|
|
|
2020-08-07 12:47:16 +00:00
|
|
|
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)
|
|
|
|
td.Vector.Pre.StateTree.RootCID = preroot
|
|
|
|
td.Vector.Post.StateTree.RootCID = postroot
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
// encode and output
|
2020-08-07 13:09:10 +00:00
|
|
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
2020-08-05 17:40:09 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}("receiver ID/Actor address does not exist")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
// TODO more tests:
|
|
|
|
// - missing/mismatched params for receiver
|
|
|
|
// - various out-of-gas cases
|
|
|
|
}
|