From f7320904bf6a294c5b1d2f0537919928b5863ea6 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 8 Dec 2022 18:07:30 +0000 Subject: [PATCH 1/3] Missed removing parameters from the operation builder --- package.json | 2 +- src/operation.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 4d70ed2ba..48d2c2418 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stellar-base", - "version": "8.0.1-soroban.5", + "version": "8.0.1-soroban.6", "description": "Low level stellar support library", "main": "./lib/index.js", "types": "./types/index.d.ts", diff --git a/src/operation.js b/src/operation.js index 7bee041af..99fbc60ce 100644 --- a/src/operation.js +++ b/src/operation.js @@ -383,7 +383,6 @@ export class Operation { case 'invokeHostFunction': { result.type = 'invokeHostFunction'; result.function = attrs.function(); - result.parameters = attrs.parameters(); result.footprint = attrs.footprint(); break; } From 66a3763e7ceac61760233383b0cf6099edb2472f Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 8 Dec 2022 19:08:53 +0000 Subject: [PATCH 2/3] Fix bug in contract.call footprint --- src/contract.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/contract.js b/src/contract.js index ee264dc5a..d840b7e29 100644 --- a/src/contract.js +++ b/src/contract.js @@ -36,21 +36,22 @@ export class Contract { * @returns {xdr.Operation} Build a InvokeHostFunctionOp operation to call the contract. */ call(method, ...params) { + let contractId = Buffer.from(this._id, 'hex'); return Operation.invokeHostFunction({ function: xdr.HostFunction.hostFunctionTypeInvokeContract([ - xdr.ScVal.scvObject( - xdr.ScObject.scoBytes(Buffer.from(this._id, 'hex')) - ), + xdr.ScVal.scvObject(xdr.ScObject.scoBytes(contractId)), xdr.ScVal.scvSymbol(method), ...params ]), // TODO: Figure out how to calculate this or get it from the user? footprint: new xdr.LedgerFootprint({ readOnly: [ - new xdr.LedgerKeyContractData({ - contractId: this._id, - key: xdr.ScVal.scvStatic(xdr.ScStatic.scsLedgerKeyContractCode()) - }) + xdr.LedgerKey.contractData( + new xdr.LedgerKeyContractData({ + contractId, + key: xdr.ScVal.scvStatic(xdr.ScStatic.scsLedgerKeyContractCode()) + }) + ) ], readWrite: [] }) From 52deccf4162acbc52c1906dcc3b18d6668a4f499 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 8 Dec 2022 19:21:49 +0000 Subject: [PATCH 3/3] Fixing up tests --- src/contract.js | 6 +++--- test/unit/contract_test.js | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/contract.js b/src/contract.js index d840b7e29..bd6f2c9cf 100644 --- a/src/contract.js +++ b/src/contract.js @@ -18,7 +18,7 @@ export class Contract { // TODO: Figure out contract owner/id stuff here. How should we represent that? constructor(contractId) { // TODO: Add methods based on the contractSpec (or do that elsewhere?) - this._id = contractId; + this._id = Buffer.from(contractId, 'hex'); } /** @@ -27,7 +27,7 @@ export class Contract { * @returns {string} */ contractId() { - return this._id; + return this._id.toString('hex'); } /** @@ -36,7 +36,7 @@ export class Contract { * @returns {xdr.Operation} Build a InvokeHostFunctionOp operation to call the contract. */ call(method, ...params) { - let contractId = Buffer.from(this._id, 'hex'); + const contractId = Buffer.from(this._id, 'hex'); return Operation.invokeHostFunction({ function: xdr.HostFunction.hostFunctionTypeInvokeContract([ xdr.ScVal.scvObject(xdr.ScObject.scoBytes(contractId)), diff --git a/test/unit/contract_test.js b/test/unit/contract_test.js index ebf0abd55..9310c4b62 100644 --- a/test/unit/contract_test.js +++ b/test/unit/contract_test.js @@ -1,17 +1,21 @@ describe('Contract.call', function() { it('includes the contract code footprint', function() { - let contractId = '00000000000000000000000000000001'; + let contractId = + '0000000000000000000000000000000000000000000000000000000000000001'; let contract = new StellarBase.Contract(contractId); + expect(contract.contractId()).to.equal(contractId); let call = contract.call('foo'); let op = call.body().invokeHostFunctionOp(); let readOnly = op.footprint().readOnly(); expect(readOnly.length).to.equal(1); - let expected = new StellarBase.xdr.LedgerKeyContractData({ - contractId, - key: StellarBase.xdr.ScVal.scvStatic( - StellarBase.xdr.ScStatic.scsLedgerKeyContractCode() - ) - }) + let expected = new StellarBase.xdr.LedgerKey.contractData( + new StellarBase.xdr.LedgerKeyContractData({ + contractId: Buffer.from(contractId, 'hex'), + key: StellarBase.xdr.ScVal.scvStatic( + StellarBase.xdr.ScStatic.scsLedgerKeyContractCode() + ) + }) + ) .toXDR() .toString('base64'); expect(readOnly[0].toXDR().toString('base64')).to.equal(expected);