Skip to content

Commit 0318fad

Browse files
committed
proof: add a test for encoding/decoding of v1 group key reveal
Add a unit test to verify that encoding and decoding work correctly when the proof group key reveal is of version 1 type.
1 parent 9765314 commit 0318fad

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

proof/proof_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,42 @@ func assertEqualProof(t *testing.T, expected, actual *Proof) {
256256
)
257257
}
258258

259+
// TestProofEncodingGroupKeyRevealV1 tests encoding and decoding a proof with a
260+
// group key reveal V1.
261+
func TestProofEncodingGroupKeyRevealV1(t *testing.T) {
262+
t.Parallel()
263+
264+
testBlocks := readTestData(t)
265+
oddTxBlock := testBlocks[0]
266+
267+
genesis := asset.RandGenesis(t, asset.Normal)
268+
scriptKey := test.RandPubKey(t)
269+
proof := RandProof(t, genesis, scriptKey, oddTxBlock, 0, 1)
270+
271+
// Override the group key reveal with a V1 reveal.
272+
internalKey := test.RandPubKey(t)
273+
customRoot := chainhash.Hash(test.RandBytes(32))
274+
groupKeyReveal, err := asset.NewGroupKeyRevealV1(
275+
*internalKey, genesis.ID(), fn.Some(customRoot),
276+
)
277+
require.NoError(t, err)
278+
279+
proof.GroupKeyReveal = &groupKeyReveal
280+
281+
file, err := NewFile(V0, proof, proof)
282+
require.NoError(t, err)
283+
proof.AdditionalInputs = []File{*file, *file}
284+
285+
var proofBuf bytes.Buffer
286+
require.NoError(t, proof.Encode(&proofBuf))
287+
proofBytes := proofBuf.Bytes()
288+
289+
var decodedProof Proof
290+
require.NoError(t, decodedProof.Decode(bytes.NewReader(proofBytes)))
291+
292+
assertEqualProof(t, &proof, &decodedProof)
293+
}
294+
259295
func TestProofEncoding(t *testing.T) {
260296
t.Parallel()
261297

0 commit comments

Comments
 (0)