MCPcopy Create free account
hub / github.com/chain/txvm / TestSignBlock

Function TestSignBlock

protocol/bc/block_test.go:163–270  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

161}
162
163func TestSignBlock(t *testing.T) {
164 var (
165 prv1 = mustDecodePrvHex("bd0fdc7670a69fda496b64277c173e17aaaedf1931f87fb11ee55c15020e8d48189d132ea856159387ea2a1beaa1749f3c60712ddff42e33996c571e276e5c12")
166 prv2 = mustDecodePrvHex("67d8117e6ae63592d329b865a5c1c714f8eec4c50c1cafb4e0e6c073513ff41a2bbc4f1d61f1764a6345495e728a268d2b17bd99cc6637f4bc9ebc8b606b178a")
167 prv3 = mustDecodePrvHex("ad08752268a613f2f96303fff27d515eba4c55d002f1804c8e743ed14b2b7335d33e67c2eed3f571935345b17d6a01de3175b9afd5b140d5a7a05270aa38cd3c")
168
169 // This is an initial block with a 2-of-3 predicate using the keys
170 // above. The ID of the initial block is
171 // c03154168e3e08aff37359bb20c1a70ac4bdf885b349e2394a8a6c87a77bf4a2.
172 initBlock = mustDecodeBlockHex("0aa1010803100120f5bea289b62c3a240966d71ebff8c6ffa71162d661a05647c15119fa493be44dff80f5214a43f8804b0ad88242004a00526a080110021a20189d132ea856159387ea2a1beaa1749f3c60712ddff42e33996c571e276e5c121a202bbc4f1d61f1764a6345495e728a268d2b17bd99cc6637f4bc9ebc8b606b178a1a20d33e67c2eed3f571935345b17d6a01de3175b9afd5b140d5a7a05270aa38cd3c")
173
174 block2 = UnsignedBlock{
175 BlockHeader: &BlockHeader{
176 Version: 3,
177 Height: 2,
178 PreviousBlockId: mustDecodeHashPtr("c03154168e3e08aff37359bb20c1a70ac4bdf885b349e2394a8a6c87a77bf4a2"),
179 TimestampMs: 1526343442294, // 1+the timestamp in the initial block
180 TransactionsRoot: new(Hash),
181 ContractsRoot: new(Hash),
182 NoncesRoot: new(Hash),
183 NextPredicate: new(Predicate),
184 },
185 }
186 blockID = block2.Hash().Bytes()
187
188 sig1 = ed25519.Sign(prv1, blockID)
189 sig2 = ed25519.Sign(prv2, blockID)
190 sig3 = ed25519.Sign(prv3, blockID)
191 )
192
193 errTooFewKeys := errors.New("too few keys")
194 cases := []struct {
195 name string
196 keys []ed25519.PrivateKey
197 wantsigs []interface{}
198 wanterr error
199 }{
200 {
201 name: "1and2",
202 keys: []ed25519.PrivateKey{prv1, prv2, nil},
203 wantsigs: []interface{}{sig1, sig2, nil},
204 },
205 {
206 name: "1and3",
207 keys: []ed25519.PrivateKey{prv1, nil, prv3},
208 wantsigs: []interface{}{sig1, nil, sig3},
209 },
210 {
211 name: "2and3",
212 keys: []ed25519.PrivateKey{nil, prv2, prv3},
213 wantsigs: []interface{}{nil, sig2, sig3},
214 },
215 {
216 name: "all",
217 keys: []ed25519.PrivateKey{prv1, prv2, prv3},
218 },
219 {
220 name: "just1",

Callers

nothing calls this directly

Calls 11

SignFunction · 0.92
NewFunction · 0.92
RootFunction · 0.92
DeepEqualFunction · 0.92
mustDecodePrvHexFunction · 0.85
mustDecodeBlockHexFunction · 0.85
mustDecodeHashPtrFunction · 0.85
SignBlockFunction · 0.85
showSigsFunction · 0.85
BytesMethod · 0.45
HashMethod · 0.45

Tested by

no test coverage detected