Skip to content

Commit a670f02

Browse files
authored
Correctly build operations via Contract.call() (#692)
* Use the correct type for functionName 🤦
1 parent ab9cea6 commit a670f02

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
### Fixed
77
* `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)).
8+
* `Contract.call()` now produces valid `Operation` XDR ([#692](https://github.com/stellar/js-stellar-base/pull/692)).
89

910

1011
## [`v10.0.0-beta.0`](https://github.com/stellar/js-stellar-base/compare/v9.0.0...v10.0.0-beta.0): Protocol 20

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stellar-base",
3-
"version": "10.0.0-beta.0",
3+
"version": "10.0.0-beta.1",
44
"description": "Low-level support library for the Stellar network.",
55
"main": "./lib/index.js",
66
"browser": {

src/contract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class Contract {
5959
func: xdr.HostFunction.hostFunctionTypeInvokeContract(
6060
new xdr.InvokeContractArgs({
6161
contractAddress: this.address().toScAddress(),
62-
functionName: xdr.ScVal.scvSymbol(method),
62+
functionName: method,
6363
args: params
6464
})
6565
),

test/unit/contract_test.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ const NULL_ADDRESS = 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM';
44
describe('Contract', function () {
55
describe('constructor', function () {
66
it('parses strkeys', function () {
7-
let contractId =
8-
'CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE';
9-
let contract = new Contract(contractId);
10-
expect(contract.contractId('strkey')).to.equal(contractId);
7+
[
8+
NULL_ADDRESS,
9+
'CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE'
10+
].forEach((cid) => {
11+
const contract = new Contract(cid);
12+
expect(contract.contractId()).to.equal(cid);
13+
});
1114
});
1215

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

62-
xit('builds valid XDR', function () {
65+
it('works with no parameters', function () {
66+
contract.call('empty').toXDR();
67+
});
68+
69+
it('builds valid XDR', function () {
6370
call.toXDR();
6471
});
6572

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

7885
it('passes the method name as the second arg', function () {
79-
expect(args.functionName()).to.deep.equal(xdr.ScVal.scvSymbol('method'));
86+
expect(args.functionName()).to.deep.equal('method');
8087
});
8188

8289
it('passes all params after that', function () {
@@ -85,9 +92,5 @@ describe('Contract', function () {
8592
xdr.ScVal.scvI32(2)
8693
]);
8794
});
88-
89-
xit('works with no parameters', function () {
90-
contract.call('empty').toXDR();
91-
});
9295
});
9396
});

0 commit comments

Comments
 (0)