Skip to content

Commit

Permalink
Correctly build operations via Contract.call() (#692)
Browse files Browse the repository at this point in the history
* Use the correct type for functionName 🤦
  • Loading branch information
Shaptic authored Sep 13, 2023
1 parent ab9cea6 commit a670f02
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Fixed
* `nativeToScVal` now allows anything to be passed to the `opts.type` specifier. Previously, it was only integer types ([#691](https://github.com/stellar/js-stellar-base/pull/691)).
* `Contract.call()` now produces valid `Operation` XDR ([#692](https://github.com/stellar/js-stellar-base/pull/692)).


## [`v10.0.0-beta.0`](https://github.com/stellar/js-stellar-base/compare/v9.0.0...v10.0.0-beta.0): Protocol 20
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stellar-base",
"version": "10.0.0-beta.0",
"version": "10.0.0-beta.1",
"description": "Low-level support library for the Stellar network.",
"main": "./lib/index.js",
"browser": {
Expand Down
2 changes: 1 addition & 1 deletion src/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Contract {
func: xdr.HostFunction.hostFunctionTypeInvokeContract(
new xdr.InvokeContractArgs({
contractAddress: this.address().toScAddress(),
functionName: xdr.ScVal.scvSymbol(method),
functionName: method,
args: params
})
),
Expand Down
23 changes: 13 additions & 10 deletions test/unit/contract_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ const NULL_ADDRESS = 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM';
describe('Contract', function () {
describe('constructor', function () {
it('parses strkeys', function () {
let contractId =
'CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE';
let contract = new Contract(contractId);
expect(contract.contractId('strkey')).to.equal(contractId);
[
NULL_ADDRESS,
'CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE'
].forEach((cid) => {
const contract = new Contract(cid);
expect(contract.contractId()).to.equal(cid);
});
});

it('throws on obsolete hex ids', function () {
Expand Down Expand Up @@ -59,7 +62,11 @@ describe('Contract', function () {
StellarBase.nativeToScVal(2, { type: 'i32' })
);

xit('builds valid XDR', function () {
it('works with no parameters', function () {
contract.call('empty').toXDR();
});

it('builds valid XDR', function () {
call.toXDR();
});

Expand All @@ -76,7 +83,7 @@ describe('Contract', function () {
});

it('passes the method name as the second arg', function () {
expect(args.functionName()).to.deep.equal(xdr.ScVal.scvSymbol('method'));
expect(args.functionName()).to.deep.equal('method');
});

it('passes all params after that', function () {
Expand All @@ -85,9 +92,5 @@ describe('Contract', function () {
xdr.ScVal.scvI32(2)
]);
});

xit('works with no parameters', function () {
contract.call('empty').toXDR();
});
});
});

0 comments on commit a670f02

Please sign in to comment.