Skip to content

Commit

Permalink
Added failing_noop operation handling (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbineshECAD authored Aug 26, 2022
1 parent 4343143 commit 8e38c79
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
19 changes: 19 additions & 0 deletions pkg/signatory/signatory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ func TestPolicy(t *testing.T) {
LogPayloads: true,
},
},
{
title: "failing noop not allowed",
msg: mustHex("05010000004254657a6f73205369676e6564204d6573736167653a206d79646170702e636f6d20323032312d30312d31345431353a31363a30345a2048656c6c6f20776f726c6421"),
policy: signatory.Policy{
AllowedOperations: []string{"generic", "block", "endorsement"},
AllowedKinds: []string{"endorsement", "seed_nonce_revelation", "activate_account", "ballot", "reveal", "origination", "delegation"},
LogPayloads: true,
},
expected: "request kind `failing_noop' is not allowed",
},
{
title: "failing noop ok",
msg: mustHex("05010000004254657a6f73205369676e6564204d6573736167653a206d79646170702e636f6d20323032312d30312d31345431353a31363a30345a2048656c6c6f20776f726c6421"),
policy: signatory.Policy{
AllowedOperations: []string{"generic", "block", "endorsement", "failing_noop"},
AllowedKinds: []string{"endorsement", "seed_nonce_revelation", "activate_account", "ballot", "reveal", "origination", "delegation"},
LogPayloads: true,
},
},
{
title: "block not allowed",
msg: mustHex("019caecab9000753d3029bc7d9a36b60cce68ade985a0a16929587166e0d3de61efff2fa31b7116bf670000000005ee3c23b04519d71c4e54089c56773c44979b3ba3d61078ade40332ad81577ae074f653e0e0000001100000001010000000800000000000753d2da051ba81185783e4cbc633cf2ba809139ef07c3e5f6c5867f930e7667b224430000cde7fbbb948e030000"),
Expand Down
21 changes: 20 additions & 1 deletion pkg/tezos/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GenericOperationRequest struct {
Contents []Operation
}

// OperationKinds returns list of uperation kinds
// OperationKinds returns list of operation kinds
func (u *GenericOperationRequest) OperationKinds() []string {
ops := make([]string, len(u.Contents))
for i, o := range u.Contents {
Expand Down Expand Up @@ -241,6 +241,15 @@ type TenderbakeEndorsementRequest struct {
func (t *TenderbakeEndorsementRequest) GetChainID() string { return t.ChainID }
func (t *TenderbakeEndorsementRequest) MessageKind() string { return "endorsement" }

type FailingNoopRequest struct {
ChainID string
*OpFailingNoop
}

// GetChainID returns chain ID
func (t *FailingNoopRequest) GetChainID() string { return t.ChainID }
func (t *FailingNoopRequest) MessageKind() string { return "failing_noop" }

func parseEmmyEndorsementRequest(buf *[]byte) (*EmmyEndorsementRequest, error) {
chainID, err := utils.GetBytes(buf, 4)
if err != nil {
Expand Down Expand Up @@ -330,6 +339,7 @@ const (
magicEmmyBlock = 0x01
magicEmmyEndorsement = 0x02
magicGenericOperation = 0x03
magicFailingNoop = 0x05
magicTenderbakeBlock = 0x11
magicPreendorsement = 0x12
magicTenderbakeEndorsement = 0x13
Expand All @@ -342,6 +352,15 @@ func parseRequest(buf *[]byte) (u UnsignedMessage, err error) {
}

switch t {
case magicFailingNoop:
b, err := utils.GetBytes(buf, 4)
if err != nil {
return nil, err
}
return &FailingNoopRequest{
ChainID: encodeBase58(pChainID, b),
}, nil

case magicEmmyBlock:
b, err := utils.GetBytes(buf, 4)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion pkg/tezos/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ func TestRequest(t *testing.T) {
},
},
},
{
data: "05010000004254657a6f73205369676e6564204d6573736167653a206d79646170702e636f6d20323032312d30312d31345431353a31363a30345a2048656c6c6f20776f726c6421",
msg: &FailingNoopRequest{
ChainID: "NetXHAiqfeSqpBH",
},
},
}

for _, c := range cases {
Expand All @@ -217,7 +223,7 @@ func TestRequest(t *testing.T) {
msg, err := parseRequest(&d)
require.NoError(t, err)
switch msg.(type) {
case *EmmyBlockRequest, *TenderbakeBlockRequest:
case *EmmyBlockRequest, *TenderbakeBlockRequest, *FailingNoopRequest:
default:
assert.Empty(t, d)
}
Expand Down

0 comments on commit 8e38c79

Please sign in to comment.