Skip to content

Commit

Permalink
Add toString() to Asset (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-wasp authored and abuiles committed Jul 18, 2019
1 parent 5e3157d commit 5538702
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,12 @@ export class Asset {
equals(asset) {
return this.code === asset.getCode() && this.issuer === asset.getIssuer();
}

toString() {
if (this.isNative()) {
return 'native';
}

return `${this.getCode()}-${this.getIssuer()}`;
}
}
17 changes: 17 additions & 0 deletions test/unit/asset_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,21 @@ describe('Asset', function() {
expect(asset.getIssuer()).to.equal(issuer);
});
});

describe('toString()', function() {
it("returns 'native' for native asset", function() {
var asset = StellarBase.Asset.native();
expect(asset.toString()).to.be.equal('native');
});

it("returns 'code-issuer' for non-native asset", function() {
var asset = new StellarBase.Asset(
'USD',
'GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ'
);
expect(asset.toString()).to.be.equal(
'USD-GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ'
);
});
});
});

0 comments on commit 5538702

Please sign in to comment.