|
4 | 4 | import { generateKey, LanguageCode, multisig, spendingKeyToWords } from '@ironfish/rust-nodejs'
|
5 | 5 | import fs from 'fs'
|
6 | 6 | import path from 'path'
|
| 7 | +import { Assert } from '../../../assert' |
7 | 8 | import { createTrustedDealerKeyPackages, useMinerBlockFixture } from '../../../testUtilities'
|
8 | 9 | import { createRouteTest } from '../../../testUtilities/routeTest'
|
9 | 10 | import { JsonEncoder } from '../../../wallet'
|
10 |
| -import { isMultisigSignerImport } from '../../../wallet/exporter' |
| 11 | +import { |
| 12 | + decodeAccountImport, |
| 13 | + isMultisigHardwareSignerImport, |
| 14 | + isMultisigSignerImport, |
| 15 | +} from '../../../wallet/exporter' |
11 | 16 | import { AccountFormat, encodeAccountImport } from '../../../wallet/exporter/account'
|
12 | 17 | import { AccountImport } from '../../../wallet/exporter/accountImport'
|
13 | 18 | import { Bech32Encoder } from '../../../wallet/exporter/encoders/bech32'
|
@@ -322,6 +327,24 @@ describe('Route wallet/importAccount', () => {
|
322 | 327 | expect(response.content.name).not.toBeNull()
|
323 | 328 |
|
324 | 329 | await routeTest.client.wallet.removeAccount({ account: testCaseFile })
|
| 330 | + |
| 331 | + const account = decodeAccountImport(testCase, { |
| 332 | + name: testCaseFile, |
| 333 | + }) |
| 334 | + |
| 335 | + if (account.multisigKeys && isMultisigHardwareSignerImport(account.multisigKeys)) { |
| 336 | + await routeTest.node.wallet.walletDb.deleteMultisigIdentity( |
| 337 | + Buffer.from(account.multisigKeys.identity, 'hex'), |
| 338 | + ) |
| 339 | + } |
| 340 | + |
| 341 | + if (account.multisigKeys && isMultisigSignerImport(account.multisigKeys)) { |
| 342 | + await routeTest.node.wallet.walletDb.deleteMultisigIdentity( |
| 343 | + new multisig.ParticipantSecret(Buffer.from(account.multisigKeys.secret, 'hex')) |
| 344 | + .toIdentity() |
| 345 | + .serialize(), |
| 346 | + ) |
| 347 | + } |
325 | 348 | }
|
326 | 349 | })
|
327 | 350 |
|
@@ -442,7 +465,7 @@ describe('Route wallet/importAccount', () => {
|
442 | 465 | expect.assertions(2)
|
443 | 466 | })
|
444 | 467 |
|
445 |
| - it('should not import multisig account with duplicate identity name', async () => { |
| 468 | + it('should not import multisig account with secret with the same identity name', async () => { |
446 | 469 | const name = 'duplicateIdentityNameTest'
|
447 | 470 |
|
448 | 471 | const {
|
@@ -527,4 +550,96 @@ describe('Route wallet/importAccount', () => {
|
527 | 550 |
|
528 | 551 | expect.assertions(7)
|
529 | 552 | })
|
| 553 | + |
| 554 | + it('should not import hardware multisig account with same identity name', async () => { |
| 555 | + const name = 'duplicateIdentityNameTest' |
| 556 | + |
| 557 | + const { |
| 558 | + dealer: trustedDealerPackages, |
| 559 | + secrets, |
| 560 | + identities, |
| 561 | + } = createTrustedDealerKeyPackages() |
| 562 | + |
| 563 | + const identity = identities[0] |
| 564 | + const nextIdentity = identities[1] |
| 565 | + |
| 566 | + await routeTest.node.wallet.walletDb.putMultisigIdentity(Buffer.from(identity, 'hex'), { |
| 567 | + secret: secrets[0].serialize(), |
| 568 | + name, |
| 569 | + }) |
| 570 | + |
| 571 | + const account: AccountImport = { |
| 572 | + version: 1, |
| 573 | + name, |
| 574 | + viewKey: trustedDealerPackages.viewKey, |
| 575 | + incomingViewKey: trustedDealerPackages.incomingViewKey, |
| 576 | + outgoingViewKey: trustedDealerPackages.outgoingViewKey, |
| 577 | + publicAddress: trustedDealerPackages.publicAddress, |
| 578 | + proofAuthorizingKey: trustedDealerPackages.proofAuthorizingKey, |
| 579 | + spendingKey: null, |
| 580 | + createdAt: null, |
| 581 | + multisigKeys: { |
| 582 | + publicKeyPackage: trustedDealerPackages.publicKeyPackage, |
| 583 | + identity: nextIdentity, |
| 584 | + }, |
| 585 | + } |
| 586 | + |
| 587 | + try { |
| 588 | + await routeTest.client.wallet.importAccount({ |
| 589 | + account: new JsonEncoder().encode(account), |
| 590 | + name, |
| 591 | + rescan: false, |
| 592 | + }) |
| 593 | + } catch (e: unknown) { |
| 594 | + if (!(e instanceof RpcRequestError)) { |
| 595 | + throw e |
| 596 | + } |
| 597 | + |
| 598 | + expect(e.status).toBe(400) |
| 599 | + expect(e.code).toBe(RPC_ERROR_CODES.DUPLICATE_IDENTITY_NAME) |
| 600 | + } |
| 601 | + |
| 602 | + expect.assertions(2) |
| 603 | + }) |
| 604 | + |
| 605 | + it('should not modify existing identity if a new one is being imported with a different name', async () => { |
| 606 | + const { dealer: trustedDealerPackages, identities } = createTrustedDealerKeyPackages() |
| 607 | + |
| 608 | + const identity = identities[0] |
| 609 | + |
| 610 | + await routeTest.node.wallet.walletDb.putMultisigIdentity(Buffer.from(identity, 'hex'), { |
| 611 | + name: 'existingIdentity', |
| 612 | + }) |
| 613 | + |
| 614 | + const account: AccountImport = { |
| 615 | + version: 1, |
| 616 | + name: 'newIdentity', |
| 617 | + viewKey: trustedDealerPackages.viewKey, |
| 618 | + incomingViewKey: trustedDealerPackages.incomingViewKey, |
| 619 | + outgoingViewKey: trustedDealerPackages.outgoingViewKey, |
| 620 | + publicAddress: trustedDealerPackages.publicAddress, |
| 621 | + proofAuthorizingKey: trustedDealerPackages.proofAuthorizingKey, |
| 622 | + spendingKey: null, |
| 623 | + createdAt: null, |
| 624 | + multisigKeys: { |
| 625 | + publicKeyPackage: trustedDealerPackages.publicKeyPackage, |
| 626 | + identity: identity, |
| 627 | + }, |
| 628 | + } |
| 629 | + |
| 630 | + const response = await routeTest.client.wallet.importAccount({ |
| 631 | + account: new JsonEncoder().encode(account), |
| 632 | + name: 'newIdentity', |
| 633 | + rescan: false, |
| 634 | + }) |
| 635 | + |
| 636 | + expect(response.status).toBe(200) |
| 637 | + expect(response.content.name).toEqual('newIdentity') |
| 638 | + |
| 639 | + const existingIdentity = await routeTest.wallet.walletDb.getMultisigIdentity( |
| 640 | + Buffer.from(identity, 'hex'), |
| 641 | + ) |
| 642 | + Assert.isNotUndefined(existingIdentity) |
| 643 | + expect(existingIdentity.name).toEqual('existingIdentity') |
| 644 | + }) |
530 | 645 | })
|
0 commit comments