Skip to content

Commit

Permalink
Add Contract.address() method (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Bellamy authored May 31, 2023
1 parent 33dcef5 commit c8d3817
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/contract.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Address } from './address';
import { Operation } from './operation';
import xdr from './xdr';
import { StrKey } from './strkey';
Expand Down Expand Up @@ -51,6 +52,14 @@ export class Contract {
}
}

/**
* Returns the address of this contract as an Address type.
* @returns {Address}
*/
address() {
return Address.contract(this._id);
}

/**
* Returns an operation that will invoke this contract call.
*
Expand Down
8 changes: 8 additions & 0 deletions test/unit/contract_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ describe('Contract', function () {
});
});

describe('address', function () {
it('returns the contract address', function () {
let contractId = '0'.repeat(63) + '1';
let contract = new StellarBase.Contract(contractId);
expect(contract.address().toBuffer().toString('hex')).to.equal(contractId);
});
});

describe('getFootprint', function () {
it('includes the correct contract code footprint', function () {
let contractId = '0'.repeat(63) + '1';
Expand Down

0 comments on commit c8d3817

Please sign in to comment.