Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Contract.address() method #614

Merged
merged 1 commit into from
May 31, 2023
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
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