(t *testing.T)
| 395 | } |
| 396 | |
| 397 | func TestMultisig(t *testing.T) { |
| 398 | ctx := context.Background() |
| 399 | |
| 400 | tpl := &Template{MaxTimeMS: bc.Millis(time.Now().Add(time.Minute))} |
| 401 | |
| 402 | var ( |
| 403 | prvkeys []ed25519.PrivateKey |
| 404 | pubkeys []ed25519.PublicKey |
| 405 | ) |
| 406 | for i := 0; i < 3; i++ { |
| 407 | pub, prv, err := ed25519.GenerateKey(nil) |
| 408 | if err != nil { |
| 409 | t.Fatal(err) |
| 410 | } |
| 411 | prvkeys = append(prvkeys, prv) |
| 412 | pubkeys = append(pubkeys, pub) |
| 413 | } |
| 414 | |
| 415 | assetID := bc.NewHash(standard.AssetID(2, 2, pubkeys, nil)) |
| 416 | |
| 417 | tpl.AddIssuance(2, nil, nil, 2, [][]byte{{0}, {1}, {2}}, nil, pubkeys, 1, nil, nil) |
| 418 | tpl.AddOutput(0, nil, 1, assetID, nil, nil) |
| 419 | err := tpl.Sign(ctx, func(_ context.Context, msg []byte, keyID []byte, _ [][]byte) ([]byte, error) { |
| 420 | if bytes.Equal(keyID, []byte{0}) { |
| 421 | return ed25519.Sign(prvkeys[0], msg), nil |
| 422 | } |
| 423 | return nil, nil |
| 424 | }) |
| 425 | if err != nil { |
| 426 | t.Fatal(err) |
| 427 | } |
| 428 | _, err = tpl.Tx() |
| 429 | if err == nil { |
| 430 | t.Errorf("got no error with 1 signature for 2-of-3 issuance") |
| 431 | } |
| 432 | |
| 433 | tpl.Dematerialize() |
| 434 | err = tpl.Sign(ctx, func(_ context.Context, msg []byte, keyID []byte, _ [][]byte) ([]byte, error) { |
| 435 | if bytes.Equal(keyID, []byte{1}) { |
| 436 | return ed25519.Sign(prvkeys[1], msg), nil |
| 437 | } |
| 438 | return nil, nil |
| 439 | }) |
| 440 | if err != nil { |
| 441 | t.Fatal(err) |
| 442 | } |
| 443 | _, err = tpl.Tx() |
| 444 | if err != nil { |
| 445 | t.Errorf("got error %s with 2 signatures for 2-of-3 issuance, want no error", err) |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | func sign(t *testing.T, tpl *Template) { |
| 450 | ctx := context.Background() |
nothing calls this directly
no test coverage detected