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:
parent
81ea0ec5f3
commit
52cf367a92
@ -123,3 +123,12 @@ func (tv TestVector) Validate() error {
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
@ -119,10 +119,7 @@ func MessageTest_AccountActorCreation() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
@ -184,10 +181,7 @@ func MessageTest_InitActorSequentialIDAddressCreate() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
abi_spec "github.com/filecoin-project/specs-actors/actors/abi"
|
abi_spec "github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
@ -40,10 +40,7 @@ func MessageTest_MessageApplicationEdgecases() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}("fail to cover gas cost for message receipt on chain")
|
}("fail to cover gas cost for message receipt on chain")
|
||||||
@ -81,10 +78,7 @@ func MessageTest_MessageApplicationEdgecases() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}("not enough gas to pay message on-chain-size cost")
|
}("not enough gas to pay message on-chain-size cost")
|
||||||
@ -132,10 +126,7 @@ func MessageTest_MessageApplicationEdgecases() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}("fail not enough gas to cover account actor creation")
|
}("fail not enough gas to cover account actor creation")
|
||||||
@ -174,10 +165,7 @@ func MessageTest_MessageApplicationEdgecases() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}("invalid actor nonce")
|
}("invalid actor nonce")
|
||||||
@ -246,10 +234,7 @@ func MessageTest_MessageApplicationEdgecases() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}("abort during actor execution")
|
}("abort during actor execution")
|
||||||
@ -281,10 +266,7 @@ func MessageTest_MessageApplicationEdgecases() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}("invalid method for receiver")
|
}("invalid method for receiver")
|
||||||
@ -325,10 +307,7 @@ func MessageTest_MessageApplicationEdgecases() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}("receiver ID/Actor address does not exist")
|
}("receiver ID/Actor address does not exist")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
abi_spec "github.com/filecoin-project/specs-actors/actors/abi"
|
abi_spec "github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
@ -55,10 +55,7 @@ func MessageTest_Paych() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}("happy path constructor")
|
}("happy path constructor")
|
||||||
@ -130,10 +127,7 @@ func MessageTest_Paych() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}("happy path update")
|
}("happy path update")
|
||||||
@ -208,10 +202,7 @@ func MessageTest_Paych() error {
|
|||||||
td.Vector.Post.StateTree.RootCID = postroot
|
td.Vector.Post.StateTree.RootCID = postroot
|
||||||
|
|
||||||
// encode and output
|
// encode and output
|
||||||
enc := json.NewEncoder(os.Stdout)
|
fmt.Fprintln(os.Stdout, string(td.Vector.MustMarshalJSON()))
|
||||||
if err := enc.Encode(&td.Vector); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}("happy path collect")
|
}("happy path collect")
|
||||||
|
Loading…
Reference in New Issue
Block a user