From c8d3817beb09167e6e9051a1fa6ac43fd673f005 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Wed, 31 May 2023 16:27:38 +0100 Subject: [PATCH] Add Contract.address() method (#614) --- src/contract.js | 9 +++++++++ test/unit/contract_test.js | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/contract.js b/src/contract.js index 7b320486..0e97dddd 100644 --- a/src/contract.js +++ b/src/contract.js @@ -1,3 +1,4 @@ +import { Address } from './address'; import { Operation } from './operation'; import xdr from './xdr'; import { StrKey } from './strkey'; @@ -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. * diff --git a/test/unit/contract_test.js b/test/unit/contract_test.js index a816ac87..9d0d9eac 100644 --- a/test/unit/contract_test.js +++ b/test/unit/contract_test.js @@ -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';