feat: add MustMarshalJSON for more DRY outputting (#211)

Small change to make encoding and printing the test vector output a bit more succinct.
This commit is contained in:
Alan Shaw 2020-08-07 14:09:10 +01:00 committed by GitHub
parent 81ea0ec5f3
commit 52cf367a92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 51 deletions

View File

@ -123,3 +123,12 @@ func (tv TestVector) Validate() error {
}
return nil
}
// MustMarshalJSON encodes the test vector to JSON and panics if it errors.
func (tv TestVector) MustMarshalJSON() []byte {
b, err := json.Marshal(&tv)
if err != nil {
panic(err)
}
return b
}

View File

@ -1,7 +1,7 @@
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/hashicorp/go-multierror"
@ -119,10 +119,7 @@ func MessageTest_AccountActorCreation() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}()
@ -184,10 +181,7 @@ func MessageTest_InitActorSequentialIDAddressCreate() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}

View File

@ -1,7 +1,7 @@
package main
import (
"encoding/json"
"fmt"
"os"
abi_spec "github.com/filecoin-project/specs-actors/actors/abi"
@ -40,10 +40,7 @@ func MessageTest_MessageApplicationEdgecases() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}("fail to cover gas cost for message receipt on chain")
@ -81,10 +78,7 @@ func MessageTest_MessageApplicationEdgecases() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}("not enough gas to pay message on-chain-size cost")
@ -132,10 +126,7 @@ func MessageTest_MessageApplicationEdgecases() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}("fail not enough gas to cover account actor creation")
@ -174,10 +165,7 @@ func MessageTest_MessageApplicationEdgecases() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}("invalid actor nonce")
@ -246,10 +234,7 @@ func MessageTest_MessageApplicationEdgecases() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}("abort during actor execution")
@ -281,10 +266,7 @@ func MessageTest_MessageApplicationEdgecases() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}("invalid method for receiver")
@ -325,10 +307,7 @@ func MessageTest_MessageApplicationEdgecases() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}("receiver ID/Actor address does not exist")

View File

@ -1,7 +1,7 @@
package main
import (
"encoding/json"
"fmt"
"os"
abi_spec "github.com/filecoin-project/specs-actors/actors/abi"
@ -55,10 +55,7 @@ func MessageTest_Paych() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}("happy path constructor")
@ -130,10 +127,7 @@ func MessageTest_Paych() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}("happy path update")
@ -208,10 +202,7 @@ func MessageTest_Paych() error {
td.Vector.Post.StateTree.RootCID = postroot
// encode and output
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(&td.Vector); err != nil {
return err
}
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
return nil
}("happy path collect")