-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tvx: a test vector extraction and execution tool #4064
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e5c56da
move conformance tvx tool to lotus.
raulk a712c10
tvx/extract: print confirmation.
raulk f5f23f7
driver: option for VM flushing.
raulk fe869c9
address review comments; lint.
raulk 9a355c4
fix lint errors.
raulk f05a40f
use lotus CLI package; document API endpoint setting in usage.
raulk dfdcbd1
add --repo flag.
raulk 8f3be78
tvx/extract: allow passing in block to speed things up.
raulk a0dffb4
tvx/extract: perform sanity check on receipt.
raulk 4c97171
tvx/extract: small refactor.
raulk 9f6862a
fix lint.
raulk 96f8828
add extract-many command.
raulk 4b3b35c
conformance: record and feed circulating supply.
raulk 9b403e2
fix lint.
raulk 0070d27
Merge pull request #4078 from filecoin-project/tvx-circsupply
raulk 0446744
fix double mutex.
raulk eb6191d
tvx: precursor selection modes; canonical message fetching; basefee.
raulk f58881e
minor fixes.
raulk ff8663f
update test-vectors submodule.
raulk 1c4f8e8
tvx/extract-many: add batch id, change generated filename.
raulk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
### Conformance testing. | ||
conformance/ @raulk | ||
extern/test-vectors @raulk | ||
cmd/tvx @raulk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/filecoin-project/specs-actors/actors/builtin" | ||
"github.com/ipfs/go-cid" | ||
"github.com/multiformats/go-multihash" | ||
) | ||
|
||
var ActorMethodTable = make(map[string][]string, 64) | ||
|
||
var Actors = map[cid.Cid]interface{}{ | ||
builtin.InitActorCodeID: builtin.MethodsInit, | ||
builtin.CronActorCodeID: builtin.MethodsCron, | ||
builtin.AccountActorCodeID: builtin.MethodsAccount, | ||
builtin.StoragePowerActorCodeID: builtin.MethodsPower, | ||
builtin.StorageMinerActorCodeID: builtin.MethodsMiner, | ||
builtin.StorageMarketActorCodeID: builtin.MethodsMarket, | ||
builtin.PaymentChannelActorCodeID: builtin.MethodsPaych, | ||
builtin.MultisigActorCodeID: builtin.MethodsMultisig, | ||
builtin.RewardActorCodeID: builtin.MethodsReward, | ||
builtin.VerifiedRegistryActorCodeID: builtin.MethodsVerifiedRegistry, | ||
} | ||
|
||
func init() { | ||
for code, methods := range Actors { | ||
cmh, err := multihash.Decode(code.Hash()) // identity hash. | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
var ( | ||
aname = string(cmh.Digest) | ||
rt = reflect.TypeOf(methods) | ||
nf = rt.NumField() | ||
) | ||
|
||
ActorMethodTable[aname] = append(ActorMethodTable[aname], "Send") | ||
for i := 0; i < nf; i++ { | ||
ActorMethodTable[aname] = append(ActorMethodTable[aname], rt.Field(i).Name) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
|
||
"github.com/fatih/color" | ||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/filecoin-project/lotus/conformance" | ||
|
||
"github.com/filecoin-project/test-vectors/schema" | ||
) | ||
|
||
var execFlags struct { | ||
file string | ||
} | ||
|
||
var execCmd = &cli.Command{ | ||
Name: "exec", | ||
Description: "execute one or many test vectors against Lotus; supplied as a single JSON file, or a ndjson stdin stream", | ||
Action: runExecLotus, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "file", | ||
Usage: "input file; if not supplied, the vector will be read from stdin", | ||
TakesFile: true, | ||
Destination: &execFlags.file, | ||
}, | ||
}, | ||
} | ||
|
||
func runExecLotus(_ *cli.Context) error { | ||
if file := execFlags.file; file != "" { | ||
// we have a single test vector supplied as a file. | ||
file, err := os.Open(file) | ||
if err != nil { | ||
return fmt.Errorf("failed to open test vector: %w", err) | ||
} | ||
|
||
var ( | ||
dec = json.NewDecoder(file) | ||
tv schema.TestVector | ||
) | ||
|
||
if err = dec.Decode(&tv); err != nil { | ||
return fmt.Errorf("failed to decode test vector: %w", err) | ||
} | ||
|
||
return executeTestVector(tv) | ||
} | ||
|
||
for dec := json.NewDecoder(os.Stdin); ; { | ||
var tv schema.TestVector | ||
switch err := dec.Decode(&tv); err { | ||
case nil: | ||
if err = executeTestVector(tv); err != nil { | ||
return err | ||
} | ||
case io.EOF: | ||
// we're done. | ||
return nil | ||
default: | ||
// something bad happened. | ||
return err | ||
} | ||
} | ||
} | ||
|
||
func executeTestVector(tv schema.TestVector) error { | ||
log.Println("executing test vector:", tv.Meta.ID) | ||
r := new(conformance.LogReporter) | ||
switch class := tv.Class; class { | ||
case "message": | ||
conformance.ExecuteMessageVector(r, &tv) | ||
case "tipset": | ||
conformance.ExecuteTipsetVector(r, &tv) | ||
default: | ||
return fmt.Errorf("test vector class %s not supported", class) | ||
} | ||
|
||
if r.Failed() { | ||
log.Println(color.HiRedString("❌ test vector failed")) | ||
} else { | ||
log.Println(color.GreenString("✅ test vector succeeded")) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With #3936 there are multiple code CIDs depending on actor version.
Ideally we would deduplicate this with the registry in chain/vm/invoker.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's anything I can do right now. When that PR lands, we can enhance the invoker so that it can be introspected from the outside and return metadata about the actors/methods it knows about. For that to be usable here, we'd need to record the method name too (probably just the name of the actor function).