Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Transaction } from './transaction/transaction';
export class CosignDelegationProposalBuilder extends TransactionBuilder {
private _contractId: string;
private _operatorId: string;
private _updateId: string;
private _packageName?: string;

constructor(_coinConfig: Readonly<CoinConfig>) {
Expand Down Expand Up @@ -63,6 +64,22 @@ export class CosignDelegationProposalBuilder extends TransactionBuilder {
return this;
}

/**
* Sets the incoming txn id (updateId of the ledger update)
* @param id - ledger update id
* @returns The current builder instance for chaining.
* @throws Error if id is empty.
*/
updateId(id: string): this {
if (!id || !id.trim()) {
throw new Error('updateId must be a non-empty string');
}
this._updateId = id.trim();
// also set the transaction id
this.transaction.id = id.trim();
return this;
}

/**
* Sets the optional package name
* @param name - package name
Expand All @@ -85,6 +102,7 @@ export class CosignDelegationProposalBuilder extends TransactionBuilder {
const result: CosignDelegationProposal = {
contractId: this._contractId,
operatorId: this._operatorId,
updateId: this._updateId,
};
if (this._packageName !== undefined) {
result.packageName = this._packageName;
Expand All @@ -101,5 +119,6 @@ export class CosignDelegationProposalBuilder extends TransactionBuilder {
private validate(): void {
if (!this._contractId) throw new Error('contractId is missing');
if (!this._operatorId) throw new Error('operatorId is missing');
if (!this._updateId) throw new Error('updateId is missing');
}
}
1 change: 1 addition & 0 deletions modules/sdk-coin-canton/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export interface TransferAcknowledge {
export interface CosignDelegationProposal {
contractId: string;
operatorId: string;
updateId: string;
packageName?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,39 @@ import { CosignDelegationProposal } from '../../../../src/lib/iface';
const contractId =
'001b549bfa833bab661ab30e4d0a3ab0ec01fcc4a2bef5369795f4928147706353ca1112205a8d0e780cf3b3115cf8be0d6315f4aed6a1c25b67e8c5d64cf9848d0458fd17';
const operatorId = '12205::12205b4e3537a95126d90604592344d8ad3c3ddccda4f79901954280ee19c576714d';
const updateId = '1220d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1';
const packageName = 'splice-amulet';
const submissionId = '12205b4e3537a95126d90604592344d8ad3c3ddccda4f79901954280ee19c576714d';

describe('CosignDelegationProposal Builder', () => {
it('should get the cosign delegation proposal request object', function () {
const txBuilder = new CosignDelegationProposalBuilder(coins.get('tcanton'));
const tx = new Transaction(coins.get('tcanton'));
tx.id = submissionId;
txBuilder.initBuilder(tx);
txBuilder.contractId(contractId).operatorId(operatorId).packageName(packageName);
txBuilder.contractId(contractId).operatorId(operatorId).updateId(updateId).packageName(packageName);
const requestObj: CosignDelegationProposal = txBuilder.toRequestObject();
should.exist(requestObj);
assert.equal(requestObj.contractId, contractId);
assert.equal(requestObj.operatorId, operatorId);
assert.equal(requestObj.updateId, updateId);
assert.equal(requestObj.packageName, packageName);
});

it('should get the cosign delegation proposal request object without packageName', function () {
const txBuilder = new CosignDelegationProposalBuilder(coins.get('tcanton'));
const tx = new Transaction(coins.get('tcanton'));
tx.id = submissionId;
txBuilder.initBuilder(tx);
txBuilder.contractId(contractId).operatorId(operatorId);
txBuilder.contractId(contractId).operatorId(operatorId).updateId(updateId);
const requestObj: CosignDelegationProposal = txBuilder.toRequestObject();
should.exist(requestObj);
assert.equal(requestObj.contractId, contractId);
assert.equal(requestObj.operatorId, operatorId);
assert.equal(requestObj.updateId, updateId);
assert.equal(requestObj.packageName, undefined);
});

it('should throw if contractId is missing', function () {
const txBuilder = new CosignDelegationProposalBuilder(coins.get('tcanton'));
const tx = new Transaction(coins.get('tcanton'));
tx.id = submissionId;
txBuilder.initBuilder(tx);
txBuilder.operatorId(operatorId);
assert.throws(() => txBuilder.toRequestObject(), /contractId is missing/);
Expand All @@ -51,7 +50,6 @@ describe('CosignDelegationProposal Builder', () => {
it('should throw if operatorId is missing', function () {
const txBuilder = new CosignDelegationProposalBuilder(coins.get('tcanton'));
const tx = new Transaction(coins.get('tcanton'));
tx.id = submissionId;
txBuilder.initBuilder(tx);
txBuilder.contractId(contractId);
assert.throws(() => txBuilder.toRequestObject(), /operatorId is missing/);
Expand All @@ -60,15 +58,13 @@ describe('CosignDelegationProposal Builder', () => {
it('should throw if contractId is empty string', function () {
const txBuilder = new CosignDelegationProposalBuilder(coins.get('tcanton'));
const tx = new Transaction(coins.get('tcanton'));
tx.id = submissionId;
txBuilder.initBuilder(tx);
assert.throws(() => txBuilder.contractId(''), /contractId must be a non-empty string/);
});

it('should throw if operatorId is empty string', function () {
const txBuilder = new CosignDelegationProposalBuilder(coins.get('tcanton'));
const tx = new Transaction(coins.get('tcanton'));
tx.id = submissionId;
txBuilder.initBuilder(tx);
assert.throws(() => txBuilder.operatorId(''), /operatorId must be a non-empty string/);
});
Expand Down
Loading