-
Notifications
You must be signed in to change notification settings - Fork 95
/
attestation_test.go
49 lines (38 loc) · 1.23 KB
/
attestation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package iotago_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/iotaledger/hive.go/lo"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/builder"
"github.com/iotaledger/iota.go/v4/tpkg"
)
func TestAttestation(t *testing.T) {
block, err := builder.NewValidationBlockBuilder(tpkg.ZeroCostTestAPI).
StrongParents(tpkg.SortedRandBlockIDs(2)).
Sign(tpkg.RandAccountID(), tpkg.RandEd25519PrivateKey()).
Build()
require.NoError(t, err)
require.Equal(t, iotago.BlockBodyTypeValidation, block.Body.Type())
attestation := iotago.NewAttestation(tpkg.ZeroCostTestAPI, block)
// Compare fields of block and attestation.
{
require.Equal(t, block.Header, attestation.Header)
require.Equal(t, lo.PanicOnErr(block.Body.Hash()), attestation.BodyHash)
require.Equal(t, block.Signature, attestation.Signature)
}
// Compare block ID and attestation block ID.
{
blockID, err := block.ID()
require.NoError(t, err)
blockIDFromAttestation, err := attestation.BlockID()
require.NoError(t, err)
require.Equal(t, blockID, blockIDFromAttestation)
}
// Check validity of signature.
{
valid, err := attestation.VerifySignature()
require.NoError(t, err)
require.True(t, valid)
}
}