feat: test driver automatically records applied messages in test vector (#212)

The `TestDriver` now records applied messages in it's `TestVector` whenever an `Apply*` method is called. This removes the need for manual message serialization and recording in the tests.
This commit is contained in:
Alan Shaw 2020-08-07 15:12:38 +01:00 committed by GitHub
parent 52cf367a92
commit a793824d2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 47 deletions

View File

@ -325,9 +325,13 @@ func (td *TestDriver) applyMessage(msg *types.Message) (result vtypes.ApplyMessa
} }
}() }()
result, err := td.applier.ApplyMessage(td.ExeCtx.Epoch, msg) epoch := td.ExeCtx.Epoch
result, err := td.applier.ApplyMessage(epoch, msg)
td.Vector.ApplyMessages = append(
td.Vector.ApplyMessages,
schema.Message{Epoch: &epoch, Bytes: chain.MustSerialize(msg)},
)
require.NoError(T, err) require.NoError(T, err)
return result return result
} }
@ -373,9 +377,13 @@ func (td *TestDriver) applyMessageSigned(msg *types.Message) (result vtypes.Appl
Message: *msg, Message: *msg,
Signature: msgSig, Signature: msgSig,
} }
result, err = td.applier.ApplySignedMessage(td.ExeCtx.Epoch, smsgs) epoch := td.ExeCtx.Epoch
result, err = td.applier.ApplySignedMessage(epoch, smsgs)
td.Vector.ApplyMessages = append(
td.Vector.ApplyMessages,
schema.Message{Epoch: &epoch, Bytes: chain.MustSerialize(smsgs)},
)
require.NoError(T, err) require.NoError(T, err)
return result return result
} }

View File

@ -15,7 +15,6 @@ import (
"github.com/filecoin-project/oni/tvx/chain" "github.com/filecoin-project/oni/tvx/chain"
"github.com/filecoin-project/oni/tvx/drivers" "github.com/filecoin-project/oni/tvx/drivers"
"github.com/filecoin-project/oni/tvx/schema"
) )
var suiteMessagesCmd = &cli.Command{ var suiteMessagesCmd = &cli.Command{
@ -96,11 +95,6 @@ func MessageTest_AccountActorCreation() error {
preroot := td.GetStateRoot() preroot := td.GetStateRoot()
msg := td.MessageProducer.Transfer(existingAccountAddr, tc.newActorAddr, chain.Value(tc.newActorInitBal), chain.Nonce(0)) msg := td.MessageProducer.Transfer(existingAccountAddr, tc.newActorAddr, chain.Value(tc.newActorInitBal), chain.Nonce(0))
b, err := msg.Serialize()
if err != nil {
return err
}
td.Vector.ApplyMessages = []schema.Message{{Bytes: b}}
result := td.ApplyFailure( result := td.ApplyFailure(
msg, msg,
tc.expExitCode, tc.expExitCode,
@ -156,24 +150,12 @@ func MessageTest_InitActorSequentialIDAddressCreate() error {
chain.MustSerialize(&firstInitRet), chain.MustSerialize(&firstInitRet),
) )
b1, err := msg1.Serialize()
if err != nil {
return err
}
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: b1})
msg2 := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(1)) msg2 := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(1))
td.ApplyExpect( td.ApplyExpect(
msg2, msg2,
chain.MustSerialize(&secondInitRet), chain.MustSerialize(&secondInitRet),
) )
b2, err := msg2.Serialize()
if err != nil {
return err
}
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: b2})
postroot := td.GetStateRoot() postroot := td.GetStateRoot()
td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot) td.Vector.CAR = td.MustMarshalGzippedCAR(preroot, postroot)

View File

@ -12,7 +12,6 @@ import (
"github.com/filecoin-project/oni/tvx/chain" "github.com/filecoin-project/oni/tvx/chain"
"github.com/filecoin-project/oni/tvx/drivers" "github.com/filecoin-project/oni/tvx/drivers"
"github.com/filecoin-project/oni/tvx/schema"
) )
func MessageTest_MessageApplicationEdgecases() error { func MessageTest_MessageApplicationEdgecases() error {
@ -27,7 +26,6 @@ func MessageTest_MessageApplicationEdgecases() error {
preroot := td.GetStateRoot() preroot := td.GetStateRoot()
msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(1), chain.GasLimit(8)) msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(1), chain.GasLimit(8))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyFailure( td.ApplyFailure(
msg, msg,
@ -55,7 +53,6 @@ func MessageTest_MessageApplicationEdgecases() error {
preroot := td.GetStateRoot() preroot := td.GetStateRoot()
msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1)) msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// Expect Message application to fail due to lack of gas // Expect Message application to fail due to lack of gas
td.ApplyFailure( td.ApplyFailure(
@ -64,7 +61,6 @@ func MessageTest_MessageApplicationEdgecases() error {
unknown := chain.MustNewIDAddr(10000000) unknown := chain.MustNewIDAddr(10000000)
msg = td.MessageProducer.Transfer(unknown, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1)) msg = td.MessageProducer.Transfer(unknown, alice, chain.Value(transferAmnt), chain.Nonce(0), chain.GasPrice(10), chain.GasLimit(1))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// Expect Message application to fail due to lack of gas when sender is unknown // Expect Message application to fail due to lack of gas when sender is unknown
td.ApplyFailure( td.ApplyFailure(
@ -100,7 +96,6 @@ func MessageTest_MessageApplicationEdgecases() error {
newAccountA := chain.MustNewSECP256K1Addr("1") newAccountA := chain.MustNewSECP256K1Addr("1")
msg := td.MessageProducer.Transfer(alice, newAccountA, chain.Value(transferAmnt), chain.Nonce(aliceNonceF())) msg := td.MessageProducer.Transfer(alice, newAccountA, chain.Value(transferAmnt), chain.Nonce(aliceNonceF()))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// get the "true" gas cost of applying the message // get the "true" gas cost of applying the message
result := td.ApplyOk(msg) result := td.ApplyOk(msg)
@ -111,7 +106,6 @@ func MessageTest_MessageApplicationEdgecases() error {
newAccountB := chain.MustNewSECP256K1Addr("2") newAccountB := chain.MustNewSECP256K1Addr("2")
for tryGas := trueGas - gasStep; tryGas > 0; tryGas -= gasStep { 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)) msg := td.MessageProducer.Transfer(alice, newAccountB, chain.Value(transferAmnt), chain.Nonce(aliceNonceF()), chain.GasPrice(1), chain.GasLimit(tryGas))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyFailure( td.ApplyFailure(
msg, msg,
@ -142,7 +136,6 @@ func MessageTest_MessageApplicationEdgecases() error {
preroot := td.GetStateRoot() preroot := td.GetStateRoot()
msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(1)) msg := td.MessageProducer.Transfer(alice, alice, chain.Value(transferAmnt), chain.Nonce(1))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// Expect Message application to fail due to callseqnum being invalid: 1 instead of 0 // Expect Message application to fail due to callseqnum being invalid: 1 instead of 0
td.ApplyFailure( td.ApplyFailure(
@ -151,7 +144,6 @@ func MessageTest_MessageApplicationEdgecases() error {
unknown := chain.MustNewIDAddr(10000000) unknown := chain.MustNewIDAddr(10000000)
msg = td.MessageProducer.Transfer(unknown, alice, chain.Value(transferAmnt), chain.Nonce(1)) msg = td.MessageProducer.Transfer(unknown, alice, chain.Value(transferAmnt), chain.Nonce(1))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// Expect message application to fail due to unknow actor when call seq num is also incorrect // Expect message application to fail due to unknow actor when call seq num is also incorrect
td.ApplyFailure( td.ApplyFailure(
@ -199,7 +191,6 @@ func MessageTest_MessageApplicationEdgecases() error {
preroot := td.GetStateRoot() preroot := td.GetStateRoot()
msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0)) msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyExpect( td.ApplyExpect(
msg, msg,
@ -220,7 +211,6 @@ func MessageTest_MessageApplicationEdgecases() error {
Signature: pcSig, // construct with invalid signature Signature: pcSig, // construct with invalid signature
}, },
}, chain.Nonce(1), chain.Value(big_spec.Zero())) }, chain.Nonce(1), chain.Value(big_spec.Zero()))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// message application fails due to invalid argument (signature). // message application fails due to invalid argument (signature).
td.ApplyFailure( td.ApplyFailure(
@ -251,8 +241,6 @@ func MessageTest_MessageApplicationEdgecases() error {
msg := td.MessageProducer.MarketComputeDataCommitment(alice, alice, nil, chain.Nonce(0)) msg := td.MessageProducer.MarketComputeDataCommitment(alice, alice, nil, chain.Nonce(0))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// message application fails because ComputeDataCommitment isn't defined // message application fails because ComputeDataCommitment isn't defined
// on the recipient actor // on the recipient actor
td.ApplyFailure( td.ApplyFailure(
@ -285,8 +273,6 @@ func MessageTest_MessageApplicationEdgecases() error {
unknownA := chain.MustNewIDAddr(10000000) unknownA := chain.MustNewIDAddr(10000000)
msg := td.MessageProducer.Transfer(alice, unknownA, chain.Value(transferAmnt), chain.Nonce(0)) msg := td.MessageProducer.Transfer(alice, unknownA, chain.Value(transferAmnt), chain.Nonce(0))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyFailure( td.ApplyFailure(
msg, msg,
exitcode_spec.SysErrInvalidReceiver) exitcode_spec.SysErrInvalidReceiver)
@ -294,7 +280,6 @@ func MessageTest_MessageApplicationEdgecases() error {
// Sending a message to non-existing actor address must produce an error. // Sending a message to non-existing actor address must produce an error.
unknownB := chain.MustNewActorAddr("1234") unknownB := chain.MustNewActorAddr("1234")
msg = td.MessageProducer.Transfer(alice, unknownB, chain.Value(transferAmnt), chain.Nonce(1)) msg = td.MessageProducer.Transfer(alice, unknownB, chain.Value(transferAmnt), chain.Nonce(1))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyFailure( td.ApplyFailure(
msg, msg,

View File

@ -12,7 +12,6 @@ import (
"github.com/filecoin-project/oni/tvx/chain" "github.com/filecoin-project/oni/tvx/chain"
"github.com/filecoin-project/oni/tvx/drivers" "github.com/filecoin-project/oni/tvx/drivers"
"github.com/filecoin-project/oni/tvx/schema"
) )
func MessageTest_Paych() error { func MessageTest_Paych() error {
@ -35,7 +34,6 @@ func MessageTest_Paych() error {
createRet := td.ComputeInitActorExecReturn(sender, 0, 0, paychAddr) createRet := td.ComputeInitActorExecReturn(sender, 0, 0, paychAddr)
msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0)) msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
// init actor creates the payment channel // init actor creates the payment channel
td.ApplyExpect( td.ApplyExpect(
@ -89,7 +87,6 @@ func MessageTest_Paych() error {
createRet := td.ComputeInitActorExecReturn(sender, 0, 0, paychAddr) createRet := td.ComputeInitActorExecReturn(sender, 0, 0, paychAddr)
msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0)) msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyExpect( td.ApplyExpect(
msg, msg,
chain.MustSerialize(&createRet)) chain.MustSerialize(&createRet))
@ -109,7 +106,6 @@ func MessageTest_Paych() error {
Signature: pcSig, Signature: pcSig,
}, },
}, chain.Nonce(1), chain.Value(big_spec.Zero())) }, chain.Nonce(1), chain.Value(big_spec.Zero()))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyOk(msg) td.ApplyOk(msg)
var pcState paych_spec.State var pcState paych_spec.State
@ -147,7 +143,6 @@ func MessageTest_Paych() error {
preroot := td.GetStateRoot() preroot := td.GetStateRoot()
msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0)) msg := td.MessageProducer.CreatePaymentChannelActor(sender, receiver, chain.Value(toSend), chain.Nonce(0))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyExpect( td.ApplyExpect(
msg, msg,
chain.MustSerialize(&initRet)) chain.MustSerialize(&initRet))
@ -172,22 +167,17 @@ func MessageTest_Paych() error {
}, },
}, chain.Nonce(1), chain.Value(big_spec.Zero())) }, chain.Nonce(1), chain.Value(big_spec.Zero()))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
td.ApplyOk(msg) td.ApplyOk(msg)
// settle the payment channel so it may be collected // settle the payment channel so it may be collected
msg = td.MessageProducer.PaychSettle(receiver, paychAddr, nil, chain.Value(big_spec.Zero()), chain.Nonce(0)) msg = td.MessageProducer.PaychSettle(receiver, paychAddr, nil, chain.Value(big_spec.Zero()), chain.Nonce(0))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Bytes: chain.MustSerialize(msg)})
settleResult := td.ApplyOk(msg) settleResult := td.ApplyOk(msg)
// advance the epoch so the funds may be redeemed. // advance the epoch so the funds may be redeemed.
td.ExeCtx.Epoch += paych_spec.SettleDelay td.ExeCtx.Epoch += paych_spec.SettleDelay
msg = td.MessageProducer.PaychCollect(receiver, paychAddr, nil, chain.Nonce(1), chain.Value(big_spec.Zero())) msg = td.MessageProducer.PaychCollect(receiver, paychAddr, nil, chain.Nonce(1), chain.Value(big_spec.Zero()))
td.Vector.ApplyMessages = append(td.Vector.ApplyMessages, schema.Message{Epoch: &td.ExeCtx.Epoch, Bytes: chain.MustSerialize(msg)})
collectResult := td.ApplyOk(msg) collectResult := td.ApplyOk(msg)
// receiver_balance = initial_balance + paych_send - settle_paych_msg_gas - collect_paych_msg_gas // receiver_balance = initial_balance + paych_send - settle_paych_msg_gas - collect_paych_msg_gas