|
| 1 | +import assert from 'assert'; |
| 2 | +import should from 'should'; |
| 3 | + |
| 4 | +import { coins } from '@bitgo/statics'; |
| 5 | + |
| 6 | +import { CosignDelegationAcceptBuilder, Transaction } from '../../../../src'; |
| 7 | +import { CantonTransferAcceptRejectRequest } from '../../../../src/lib/iface'; |
| 8 | + |
| 9 | +const commandId = '3935a06d-3b03-41be-99a5-95b2ecaabf7d'; |
| 10 | +const contractId = |
| 11 | + '001b549bfa833bab661ab30e4d0a3ab0ec01fcc4a2bef5369795f4928147706353ca1112205a8d0e780cf3b3115cf8be0d6315f4aed6a1c25b67e8c5d64cf9848d0458fd17'; |
| 12 | +const actAsPartyId = '12205::12205b4e3537a95126d90604592344d8ad3c3ddccda4f79901954280ee19c576714d'; |
| 13 | + |
| 14 | +describe('CosignDelegationAccept Builder', () => { |
| 15 | + it('should get the cosign delegation accept request object', function () { |
| 16 | + const txBuilder = new CosignDelegationAcceptBuilder(coins.get('tcanton')); |
| 17 | + const tx = new Transaction(coins.get('tcanton')); |
| 18 | + txBuilder.initBuilder(tx); |
| 19 | + txBuilder.commandId(commandId).contractId(contractId).actAs(actAsPartyId); |
| 20 | + const requestObj: CantonTransferAcceptRejectRequest = txBuilder.toRequestObject(); |
| 21 | + should.exist(requestObj); |
| 22 | + assert.equal(requestObj.commandId, commandId); |
| 23 | + assert.equal(requestObj.contractId, contractId); |
| 24 | + assert.equal(requestObj.actAs.length, 1); |
| 25 | + assert.equal(requestObj.actAs[0], actAsPartyId); |
| 26 | + assert.deepEqual(requestObj.readAs, []); |
| 27 | + assert.equal(requestObj.verboseHashing, false); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should set transaction id from commandId', function () { |
| 31 | + const txBuilder = new CosignDelegationAcceptBuilder(coins.get('tcanton')); |
| 32 | + const tx = new Transaction(coins.get('tcanton')); |
| 33 | + txBuilder.initBuilder(tx); |
| 34 | + txBuilder.commandId(commandId); |
| 35 | + assert.equal(txBuilder.transaction.id, commandId); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should throw if commandId is missing', function () { |
| 39 | + const txBuilder = new CosignDelegationAcceptBuilder(coins.get('tcanton')); |
| 40 | + const tx = new Transaction(coins.get('tcanton')); |
| 41 | + txBuilder.initBuilder(tx); |
| 42 | + txBuilder.contractId(contractId).actAs(actAsPartyId); |
| 43 | + assert.throws(() => txBuilder.toRequestObject(), /commandId is missing/); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should throw if contractId is missing', function () { |
| 47 | + const txBuilder = new CosignDelegationAcceptBuilder(coins.get('tcanton')); |
| 48 | + const tx = new Transaction(coins.get('tcanton')); |
| 49 | + txBuilder.initBuilder(tx); |
| 50 | + txBuilder.commandId(commandId).actAs(actAsPartyId); |
| 51 | + assert.throws(() => txBuilder.toRequestObject(), /contractId is missing/); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should throw if actAs is missing', function () { |
| 55 | + const txBuilder = new CosignDelegationAcceptBuilder(coins.get('tcanton')); |
| 56 | + const tx = new Transaction(coins.get('tcanton')); |
| 57 | + txBuilder.initBuilder(tx); |
| 58 | + txBuilder.commandId(commandId).contractId(contractId); |
| 59 | + assert.throws(() => txBuilder.toRequestObject(), /actAs partyId is missing/); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should throw if commandId is empty string', function () { |
| 63 | + const txBuilder = new CosignDelegationAcceptBuilder(coins.get('tcanton')); |
| 64 | + const tx = new Transaction(coins.get('tcanton')); |
| 65 | + txBuilder.initBuilder(tx); |
| 66 | + assert.throws(() => txBuilder.commandId(''), /commandId must be a non-empty string/); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should throw if contractId is empty string', function () { |
| 70 | + const txBuilder = new CosignDelegationAcceptBuilder(coins.get('tcanton')); |
| 71 | + const tx = new Transaction(coins.get('tcanton')); |
| 72 | + txBuilder.initBuilder(tx); |
| 73 | + assert.throws(() => txBuilder.contractId(''), /contractId must be a non-empty string/); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should throw if actAs is empty string', function () { |
| 77 | + const txBuilder = new CosignDelegationAcceptBuilder(coins.get('tcanton')); |
| 78 | + const tx = new Transaction(coins.get('tcanton')); |
| 79 | + txBuilder.initBuilder(tx); |
| 80 | + assert.throws(() => txBuilder.actAs(''), /actAsPartyId must be a non-empty string/); |
| 81 | + }); |
| 82 | +}); |
0 commit comments