Skip to content

Commit

Permalink
Drop incorrect key entry for contract footprint (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Nov 2, 2023
1 parent f024014 commit 16be869
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `xdr.SorobanTransactionData.refundableFee` is now `resourceFee`
- In turn, `SorobanDataBuilder.setRefundableFee` is now `setResourceFee`
- This new fee encompasses the entirety of the Soroban-related resource fees. Note that this is distinct from the "network-inclusion" fee that you would set on your transaction (i.e. `TransactionBuilder(..., { fee: ... })`).
- `Contract.getFootprint()` now only returns a single result: the ledger key of the deployed instance for the given ID, because the key for the code entry was incorrect (it should not be the ID but rather the WASM hash, which is not calculatable w/o network access) ([#709](https://github.com/stellar/js-stellar-base/pull/709)).


## [`v10.0.0-beta.3`](https://github.com/stellar/js-stellar-base/compare/v10.0.0-beta.2...v10.0.0-beta.3)
Expand Down
26 changes: 10 additions & 16 deletions src/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,18 @@ export class Contract {

/**
* Returns the read-only footprint entries necessary for any invocations to
* this contract, for convenience when adding it to your transaction's overall
* footprint or doing bump/restore operations.
* this contract, for convenience when manually adding it to your
* transaction's overall footprint or doing bump/restore operations.
*
* @returns {xdr.LedgerKey[]} the ledger keys containing the contract's code
* (first) and its deployed contract instance (second)
* @returns {xdr.LedgerKey} the ledger key for the deployed contract instance
*/
getFootprint() {
return [
xdr.LedgerKey.contractCode(
new xdr.LedgerKeyContractCode({ hash: this._id })
),
xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: this.address().toScAddress(),
key: xdr.ScVal.scvLedgerKeyContractInstance(),
durability: xdr.ContractDataDurability.persistent()
})
)
];
return xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: this.address().toScAddress(),
key: xdr.ScVal.scvLedgerKeyContractInstance(),
durability: xdr.ContractDataDurability.persistent()
})
);
}
}
21 changes: 7 additions & 14 deletions test/unit/contract_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,13 @@ describe('Contract', function () {
expect(contract.contractId()).to.equal(NULL_ADDRESS);

const actual = contract.getFootprint();
const expected = [
new xdr.LedgerKey.contractCode(
new xdr.LedgerKeyContractCode({
hash: StellarBase.StrKey.decodeContract(contract.contractId())
})
),
new xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: contract.address().toScAddress(),
key: xdr.ScVal.scvLedgerKeyContractInstance(),
durability: xdr.ContractDataDurability.persistent()
})
)
];
const expected = new xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: contract.address().toScAddress(),
key: xdr.ScVal.scvLedgerKeyContractInstance(),
durability: xdr.ContractDataDurability.persistent()
})
);

expect(actual).to.eql(expected);
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/sorobandata_builder_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ describe('SorobanTransactionData can be built', function () {
const c = new StellarBase.Contract(contractId);

const sentinel = new xdr.SorobanTransactionData({
ext: new xdr.ExtensionPoint(0),
resources: new xdr.SorobanResources({
footprint: new xdr.LedgerFootprint({ readOnly: [], readWrite: [] }),
instructions: 1,
readBytes: 2,
writeBytes: 3
}),
ext: new xdr.ExtensionPoint(0),
resourceFee: new xdr.Int64(5)
});

const key = c.getFootprint()[0];
const key = c.getFootprint(); // arbitrary key for testing

it('constructs from xdr, base64, and nothing', function () {
new dataBuilder();
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Contract {
call(method: string, ...params: xdr.ScVal[]): xdr.Operation<Operation.InvokeHostFunction>;
contractId(): string;
address(): Address;
getFootprint(): xdr.LedgerKey[];
getFootprint(): xdr.LedgerKey;

toString(): string;
}
Expand Down

0 comments on commit 16be869

Please sign in to comment.