-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement malfeasance2 info method for GRPC API (#6566)
## Motivation Followup for #6557. Now malfeasance2 proofs are actually fetched from the DB and metadata for them returned.
- Loading branch information
Showing
43 changed files
with
1,260 additions
and
176 deletions.
There are no files selected for viewing
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
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
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
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
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
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,91 @@ | ||
package activation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/spacemeshos/go-spacemesh/activation/wire" | ||
"github.com/spacemeshos/go-spacemesh/codec" | ||
) | ||
|
||
type testMalHandler struct { | ||
*MalfeasanceHandlerV2 | ||
} | ||
|
||
func newTestMalHandler(tb testing.TB) *testMalHandler { | ||
handler := NewMalfeasanceHandlerV2() | ||
|
||
return &testMalHandler{ | ||
MalfeasanceHandlerV2: handler, | ||
} | ||
} | ||
|
||
func TestHandler_Info(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("decode proof error", func(t *testing.T) { | ||
t.Parallel() | ||
th := newTestMalHandler(t) | ||
|
||
info, err := th.Info([]byte("invalid proof")) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "decoding ATX malfeasance proof") | ||
require.Nil(t, info) | ||
}) | ||
|
||
tt := []struct { | ||
name string | ||
proofType wire.ProofType | ||
proof wire.Proof | ||
}{ | ||
{ | ||
name: "double marry proof", | ||
proofType: wire.DoubleMarry, | ||
proof: &wire.ProofDoubleMarry{}, | ||
}, | ||
{ | ||
name: "double merge proof", | ||
proofType: wire.DoubleMerge, | ||
proof: &wire.ProofDoubleMerge{}, | ||
}, | ||
{ | ||
name: "invalid post", | ||
proofType: wire.InvalidPost, | ||
proof: &wire.ProofInvalidPost{}, | ||
}, | ||
{ | ||
name: "invalid prev atx v1", | ||
proofType: wire.InvalidPreviousV1, | ||
proof: &wire.ProofInvalidPrevAtxV1{}, | ||
}, | ||
{ | ||
name: "invalid prev atx v2", | ||
proofType: wire.InvalidPreviousV2, | ||
proof: &wire.ProofInvalidPrevAtxV2{}, | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
th := newTestMalHandler(t) | ||
|
||
atxProof := &wire.ATXProof{ | ||
Version: wire.ProofVersion(1), | ||
|
||
ProofType: tc.proofType, | ||
Proof: codec.MustEncode(tc.proof), | ||
} | ||
data, err := codec.Encode(atxProof) | ||
require.NoError(t, err) | ||
|
||
expectedInfo := tc.proof.Info() | ||
expectedInfo["type"] = tc.proof.String() | ||
|
||
info, err := th.Info(data) | ||
require.NoError(t, err) | ||
require.Equal(t, expectedInfo, info) | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.