Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Minimal Payment Channel Tests (#54)
Browse files Browse the repository at this point in the history
* remove extraneous require call from multisig
* add paych methods and types
* add paych constructor test and state helper
* correct signature marshaling code
* add signingbytes method to voucher
* add sign method to statewrapper
  • Loading branch information
frrist authored Dec 4, 2019
1 parent da2d45e commit d3faa5b
Show file tree
Hide file tree
Showing 11 changed files with 674 additions and 77 deletions.
37 changes: 37 additions & 0 deletions pkg/chain/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/filecoin-project/chain-validation/pkg/state/actors"
"github.com/filecoin-project/chain-validation/pkg/state/actors/initialize"
"github.com/filecoin-project/chain-validation/pkg/state/actors/multsig"
"github.com/filecoin-project/chain-validation/pkg/state/actors/paych"
"github.com/filecoin-project/chain-validation/pkg/state/actors/strgminr"
"github.com/filecoin-project/chain-validation/pkg/state/actors/strgpwr"
"github.com/filecoin-project/chain-validation/pkg/state/address"
Expand Down Expand Up @@ -60,6 +61,13 @@ const (
MultiSigSwapSigner
MultiSigChangeRequirement

PaymentChannelConstructor
PaymentChannelUpdate
PaymentChannelClose
PaymentChannelCollect
PaymentChannelGetOwner
PaymentChannelGetToSend

GetSectorSize
CronConstructor
CronTick
Expand Down Expand Up @@ -328,4 +336,33 @@ func (mp *MessageProducer) MultiSigChangeRequirement(to, from address.Address, n
return mp.Build(from, to, nonce, MultiSigChangeRequirement, params, opts...)
}

//
// Payment Channel Actor Methods
//

func (mp *MessageProducer) PaychUpdateChannelState(to, from address.Address, nonce uint64, sv types.SignedVoucher, secret, proof []byte, opts ...MsgOpt) (interface{}, error) {
params, err := types.Serialize(&paych.PaymentChannelUpdateParams{
Sv: sv,
Secret: secret,
Proof: proof,
})
if err != nil {
return nil, err
}
return mp.Build(from, to, nonce, PaymentChannelUpdate, params, opts...)
}

func (mp *MessageProducer) PaychClose(to, from address.Address, nonce uint64, opts ...MsgOpt) (interface{}, error) {
return mp.Build(from, to, nonce, PaymentChannelClose, noParams, opts...)
}
func (mp *MessageProducer) PaychCollect(to, from address.Address, nonce uint64, opts ...MsgOpt) (interface{}, error) {
return mp.Build(from, to, nonce, PaymentChannelCollect, noParams, opts...)
}
func (mp *MessageProducer) PaychGetOwner(to, from address.Address, nonce uint64, opts ...MsgOpt) (interface{}, error) {
return mp.Build(from, to, nonce, PaymentChannelGetOwner, noParams, opts...)
}
func (mp *MessageProducer) PaychGetToSend(to, from address.Address, nonce uint64, opts ...MsgOpt) (interface{}, error) {
return mp.Build(from, to, nonce, PaymentChannelGetToSend, noParams, opts...)
}

var noParams []byte
4 changes: 3 additions & 1 deletion pkg/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func main() {
types.SignedVoucher{},
types.Merge{},
types.ModVerifyParams{},
types.Signature{},
); err != nil {
panic(err)
}
Expand All @@ -35,6 +34,9 @@ func main() {
paych.PaymentInfo{},
paych.PaymentChannelActorState{},
paych.LaneState{},
paych.PaymentChannelConstructorParams{},
paych.PaymentChannelUpdateParams{},
paych.PaymentVerifyParams{},
); err != nil {
panic(err)
}
Expand Down
218 changes: 216 additions & 2 deletions pkg/state/actors/paych/cbor_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"io"
"sort"

"github.com/filecoin-project/chain-validation/pkg/state/types"
cbg "github.com/whyrusleeping/cbor-gen"
xerrors "golang.org/x/xerrors"

"github.com/filecoin-project/chain-validation/pkg/state/types"
)

/* This file was generated by github.com/whyrusleeping/cbor-gen */
Expand Down Expand Up @@ -405,3 +404,218 @@ func (t *LaneState) UnmarshalCBOR(r io.Reader) error {
t.Nonce = uint64(extra)
return nil
}

func (t *PaymentChannelConstructorParams) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{129}); err != nil {
return err
}

// t.t.To (address.Address) (struct)
if err := t.To.MarshalCBOR(w); err != nil {
return err
}
return nil
}

func (t *PaymentChannelConstructorParams) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)

maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}

if extra != 1 {
return fmt.Errorf("cbor input had wrong number of fields")
}

// t.t.To (address.Address) (struct)

{

if err := t.To.UnmarshalCBOR(br); err != nil {
return err
}

}
return nil
}

func (t *PaymentChannelUpdateParams) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{131}); err != nil {
return err
}

// t.t.Sv (types.SignedVoucher) (struct)
if err := t.Sv.MarshalCBOR(w); err != nil {
return err
}

// t.t.Secret ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Secret)))); err != nil {
return err
}
if _, err := w.Write(t.Secret); err != nil {
return err
}

// t.t.Proof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
if _, err := w.Write(t.Proof); err != nil {
return err
}
return nil
}

func (t *PaymentChannelUpdateParams) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)

maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}

if extra != 3 {
return fmt.Errorf("cbor input had wrong number of fields")
}

// t.t.Sv (types.SignedVoucher) (struct)

{

if err := t.Sv.UnmarshalCBOR(br); err != nil {
return err
}

}
// t.t.Secret ([]uint8) (slice)

maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Secret: array too large (%d)", extra)
}

if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Secret = make([]byte, extra)
if _, err := io.ReadFull(br, t.Secret); err != nil {
return err
}
// t.t.Proof ([]uint8) (slice)

maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Proof: array too large (%d)", extra)
}

if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Proof = make([]byte, extra)
if _, err := io.ReadFull(br, t.Proof); err != nil {
return err
}
return nil
}

func (t *PaymentVerifyParams) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}

// t.t.Extra ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Extra)))); err != nil {
return err
}
if _, err := w.Write(t.Extra); err != nil {
return err
}

// t.t.Proof ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Proof)))); err != nil {
return err
}
if _, err := w.Write(t.Proof); err != nil {
return err
}
return nil
}

func (t *PaymentVerifyParams) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)

maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}

if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}

// t.t.Extra ([]uint8) (slice)

maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Extra: array too large (%d)", extra)
}

if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Extra = make([]byte, extra)
if _, err := io.ReadFull(br, t.Extra); err != nil {
return err
}
// t.t.Proof ([]uint8) (slice)

maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Proof: array too large (%d)", extra)
}

if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Proof = make([]byte, extra)
if _, err := io.ReadFull(br, t.Proof); err != nil {
return err
}
return nil
}
15 changes: 15 additions & 0 deletions pkg/state/actors/paych/payment_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,18 @@ type PaymentChannelActorState struct {
// waiting on refmt#35 to be fixed
LaneStates map[string]*LaneState
}

type PaymentChannelConstructorParams struct {
To address.Address
}

type PaymentChannelUpdateParams struct {
Sv types.SignedVoucher
Secret []byte
Proof []byte
}

type PaymentVerifyParams struct {
Extra []byte
Proof []byte
}
72 changes: 0 additions & 72 deletions pkg/state/types/cbor_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,75 +369,3 @@ func (t *ModVerifyParams) UnmarshalCBOR(r io.Reader) error {
}
return nil
}

func (t *Signature) MarshalCBOR(w io.Writer) error {
if t == nil {
_, err := w.Write(cbg.CborNull)
return err
}
if _, err := w.Write([]byte{130}); err != nil {
return err
}

// t.t.Type (string) (string)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Type)))); err != nil {
return err
}
if _, err := w.Write([]byte(t.Type)); err != nil {
return err
}

// t.t.Data ([]uint8) (slice)
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil {
return err
}
if _, err := w.Write(t.Data); err != nil {
return err
}
return nil
}

func (t *Signature) UnmarshalCBOR(r io.Reader) error {
br := cbg.GetPeeker(r)

maj, extra, err := cbg.CborReadHeader(br)
if err != nil {
return err
}
if maj != cbg.MajArray {
return fmt.Errorf("cbor input should be of type array")
}

if extra != 2 {
return fmt.Errorf("cbor input had wrong number of fields")
}

// t.t.Type (string) (string)

{
sval, err := cbg.ReadString(br)
if err != nil {
return err
}

t.Type = string(sval)
}
// t.t.Data ([]uint8) (slice)

maj, extra, err = cbg.CborReadHeader(br)
if err != nil {
return err
}
if extra > 8192 {
return fmt.Errorf("t.Data: array too large (%d)", extra)
}

if maj != cbg.MajByteString {
return fmt.Errorf("expected byte array")
}
t.Data = make([]byte, extra)
if _, err := io.ReadFull(br, t.Data); err != nil {
return err
}
return nil
}
Loading

0 comments on commit d3faa5b

Please sign in to comment.