tvx/extract: perform sanity check on receipt.
This commit is contained in:
parent
8f3be78667
commit
a0dffb44d3
@ -10,6 +10,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
|
||||||
@ -277,6 +279,25 @@ func runExtract(c *cli.Context) error {
|
|||||||
return fmt.Errorf("unknown state retention option: %s", retention)
|
return fmt.Errorf("unknown state retention option: %s", retention)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("message applied; preroot: %s, postroot: %s", preroot, postroot)
|
||||||
|
log.Printf("performing sanity check on receipt")
|
||||||
|
|
||||||
|
receipt := &schema.Receipt{
|
||||||
|
ExitCode: int64(applyret.ExitCode),
|
||||||
|
ReturnValue: applyret.Return,
|
||||||
|
GasUsed: applyret.GasUsed,
|
||||||
|
}
|
||||||
|
|
||||||
|
reporter := new(conformance.LogReporter)
|
||||||
|
conformance.AssertMsgResult(reporter, receipt, applyret, "as locally executed")
|
||||||
|
if reporter.Failed() {
|
||||||
|
log.Printf(color.RedString("receipt sanity check failed; aborting"))
|
||||||
|
return fmt.Errorf("vector generation aborted")
|
||||||
|
} else {
|
||||||
|
log.Printf(color.GreenString("receipt sanity check succeeded"))
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("generating vector")
|
||||||
msgBytes, err := msg.Serialize()
|
msgBytes, err := msg.Serialize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -311,11 +332,15 @@ func runExtract(c *cli.Context) error {
|
|||||||
Class: schema.ClassMessage,
|
Class: schema.ClassMessage,
|
||||||
Meta: &schema.Metadata{
|
Meta: &schema.Metadata{
|
||||||
ID: extractFlags.id,
|
ID: extractFlags.id,
|
||||||
|
// TODO need to replace schema.GenerationData with a more flexible
|
||||||
|
// data structure that makes no assumption about the traceability
|
||||||
|
// data that's being recorded; a flexible map[string]string
|
||||||
|
// would do.
|
||||||
Gen: []schema.GenerationData{
|
Gen: []schema.GenerationData{
|
||||||
{Source: fmt.Sprintf("network:%s", ntwkName)},
|
{Source: fmt.Sprintf("network:%s", ntwkName)},
|
||||||
{Source: fmt.Sprintf("msg:%s", msg.Cid().String())},
|
{Source: fmt.Sprintf("message:%s", msg.Cid().String())},
|
||||||
{Source: fmt.Sprintf("inc_ts:%s", incTs.Key().String())},
|
{Source: fmt.Sprintf("inclusion_tipset:%s", incTs.Key().String())},
|
||||||
{Source: fmt.Sprintf("exec_ts:%s", execTs.Key().String())},
|
{Source: fmt.Sprintf("execution_tipset:%s", execTs.Key().String())},
|
||||||
{Source: "github.com/filecoin-project/lotus", Version: version.String()}},
|
{Source: "github.com/filecoin-project/lotus", Version: version.String()}},
|
||||||
},
|
},
|
||||||
CAR: out.Bytes(),
|
CAR: out.Bytes(),
|
||||||
|
@ -65,7 +65,7 @@ func ExecuteMessageVector(r Reporter, vector *schema.TestVector) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Assert that the receipt matches what the test vector expects.
|
// Assert that the receipt matches what the test vector expects.
|
||||||
assertMsgResult(r, vector.Post.Receipts[i], ret, strconv.Itoa(i))
|
AssertMsgResult(r, vector.Post.Receipts[i], ret, strconv.Itoa(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Once all messages are applied, assert that the final state root matches
|
// Once all messages are applied, assert that the final state root matches
|
||||||
@ -105,7 +105,7 @@ func ExecuteTipsetVector(r Reporter, vector *schema.TestVector) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for j, v := range ret.AppliedResults {
|
for j, v := range ret.AppliedResults {
|
||||||
assertMsgResult(r, vector.Post.Receipts[receiptsIdx], v, fmt.Sprintf("%d of tipset %d", j, i))
|
AssertMsgResult(r, vector.Post.Receipts[receiptsIdx], v, fmt.Sprintf("%d of tipset %d", j, i))
|
||||||
receiptsIdx++
|
receiptsIdx++
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,10 +127,10 @@ func ExecuteTipsetVector(r Reporter, vector *schema.TestVector) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// assertMsgResult compares a message result. It takes the expected receipt
|
// AssertMsgResult compares a message result. It takes the expected receipt
|
||||||
// encoded in the vector, the actual receipt returned by Lotus, and a message
|
// encoded in the vector, the actual receipt returned by Lotus, and a message
|
||||||
// label to log in the assertion failure message to facilitate debugging.
|
// label to log in the assertion failure message to facilitate debugging.
|
||||||
func assertMsgResult(r Reporter, expected *schema.Receipt, actual *vm.ApplyRet, label string) {
|
func AssertMsgResult(r Reporter, expected *schema.Receipt, actual *vm.ApplyRet, label string) {
|
||||||
r.Helper()
|
r.Helper()
|
||||||
|
|
||||||
if expected, actual := exitcode.ExitCode(expected.ExitCode), actual.ExitCode; expected != actual {
|
if expected, actual := exitcode.ExitCode(expected.ExitCode), actual.ExitCode; expected != actual {
|
||||||
|
Loading…
Reference in New Issue
Block a user