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

Function TestSigBits

protocol/txbuilder/txbuilder_test.go:360–395  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

358}
359
360func TestSigBits(t *testing.T) {
361 ctx := context.Background()
362
363 tpl := &Template{MaxTimeMS: bc.Millis(time.Now().Add(time.Minute))}
364
365 pub, prv, err := ed25519.GenerateKey(nil)
366 if err != nil {
367 t.Fatal(err)
368 }
369 pubkeys := []ed25519.PublicKey{pub}
370 assetID := bc.NewHash(standard.AssetID(2, 1, pubkeys, nil))
371
372 tpl.AddIssuance(2, nil, nil, 1, [][]byte{{0}}, nil, pubkeys, 1, nil, nil)
373 tpl.AddOutput(0, nil, 1, assetID, nil, nil)
374 err = tpl.Sign(ctx, func(_ context.Context, msg []byte, keyID []byte, _ [][]byte) ([]byte, error) {
375 return ed25519.Sign(prv, msg), nil
376 })
377 if err != nil {
378 t.Fatal(err)
379 }
380 _, err = tpl.Tx()
381 if err != nil {
382 t.Fatal(err)
383 }
384 for i := 0; i < len(tpl.Issuances[0].Sigs[0]); i++ {
385 for j := uint(0); j < 8; j++ {
386 tpl.Issuances[0].Sigs[0][i] ^= 1 << j
387 tpl.Dematerialize()
388 _, err = tpl.Tx()
389 if err == nil {
390 t.Errorf("got no error with twiddled bit %d", uint(8*i)+j)
391 }
392 tpl.Issuances[0].Sigs[0][i] ^= 1 << j // put it back the way it was
393 }
394 }
395}
396
397func TestMultisig(t *testing.T) {
398 ctx := context.Background()

Callers

nothing calls this directly

Calls 11

AddIssuanceMethod · 0.95
AddOutputMethod · 0.95
SignMethod · 0.95
TxMethod · 0.95
DematerializeMethod · 0.95
MillisFunction · 0.92
GenerateKeyFunction · 0.92
NewHashFunction · 0.92
AssetIDFunction · 0.92
SignFunction · 0.92
AddMethod · 0.45

Tested by

no test coverage detected