MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestBlock

Function TestBlock

xenomint/types/block_test.go:30–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestBlock(t *testing.T) {
31 Convey("Given a block and a pair of keys", t, func() {
32 var (
33 block = &Block{
34 SignedBlockHeader: SignedBlockHeader{
35 BlockHeader: BlockHeader{},
36 },
37 ReadQueries: []*types.Ack{
38 {
39 Header: types.SignedAckHeader{
40 DefaultHashSignVerifierImpl: verifier.DefaultHashSignVerifierImpl{
41 DataHash: hash.Hash{0x0, 0x0, 0x0, 0x1},
42 },
43 },
44 },
45 },
46 WriteQueries: []*types.Ack{
47 {
48 Header: types.SignedAckHeader{
49 DefaultHashSignVerifierImpl: verifier.DefaultHashSignVerifierImpl{
50 DataHash: hash.Hash{0x0, 0x0, 0x0, 0x2},
51 },
52 },
53 },
54 },
55 }
56 priv, _, err = asymmetric.GenSecp256k1KeyPair()
57 )
58 So(err, ShouldBeNil)
59 So(priv, ShouldNotBeNil)
60 Convey("When the block is signed by the key pair", func() {
61 err = block.Sign(priv)
62 So(err, ShouldBeNil)
63 Convey("The block should be verifiable", func() {
64 err = block.Verify()
65 So(err, ShouldBeNil)
66 })
67 Convey("The object should have data hash", func() {
68 var enc, err = block.BlockHeader.MarshalHash()
69 So(err, ShouldBeNil)
70 So(enc, ShouldNotBeNil)
71 So(block.SignedBlockHeader.Hash(), ShouldEqual, hash.THashH(enc))
72 })
73 Convey("When the queries is modified", func() {
74 block.ReadQueries = append(block.ReadQueries, &types.Ack{
75 Header: types.SignedAckHeader{
76 DefaultHashSignVerifierImpl: verifier.DefaultHashSignVerifierImpl{
77 DataHash: hash.Hash{0x0, 0x0, 0x0, 0x3},
78 },
79 },
80 })
81 Convey("The verifier should return merkle root not match error", func() {
82 err = block.Verify()
83 So(err, ShouldEqual, ErrMerkleRootNotMatch)
84 })
85 })
86 })
87 })

Callers

nothing calls this directly

Calls 6

GenSecp256k1KeyPairFunction · 0.92
THashHFunction · 0.92
SignMethod · 0.65
VerifyMethod · 0.65
MarshalHashMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected