Skip to content

Commit

Permalink
Prepare v0.9.0 for release. (#107)
Browse files Browse the repository at this point in the history
* Add test case for #108
* Upgrade all dependencies to their latest minor versions
  • Loading branch information
Shaptic committed Jul 11, 2023
1 parent a615931 commit 2ef1ea2
Show file tree
Hide file tree
Showing 5 changed files with 351 additions and 258 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ A breaking change should be clearly marked in this log.
## Unreleased


## v0.9.0

### Updated
* `Server.getContractData` has an additional, optional parameter: `expirationType?: string` which should be set to either `'temporary'` or `'persistent'` depending on the type of ledger key. By default, it will attempt to fetch both, returning whichever one it finds ([#103](https://github.com/stellar/js-soroban-client/pull/103)).
* `assembleTransaction` now accepts simulation results for the new `BumpFootprintExpirationOp`s and `RestoreFootprintOp`s ([#108](https://github.com/stellar/js-soroban-client/pull/108)).
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": "soroban-client",
"version": "0.8.1",
"version": "0.9.0",
"description": "A library for working with Stellar's Soroban RPC servers.",
"author": "Stellar Development Foundation <[email protected]>",
"homepage": "https://github.com/stellar/js-soroban-client",
Expand Down
3 changes: 3 additions & 0 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export function assembleTransaction(
break;

case "bumpFootprintExpiration":
txnBuilder.addOperation(Operation.bumpFootprintExpiration(raw.operations[0]));
break;

case "restoreFootprint":
txnBuilder.addOperation(Operation.restoreFootprint(raw.operations[0]));
break;
Expand Down
79 changes: 52 additions & 27 deletions test/unit/transaction_test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const xdr = SorobanClient.xdr; // shorthand

describe("assembleTransaction", () => {
describe("FeeBumpTransaction", () => {
// TODO: Add support for fee bump transactions
Expand All @@ -7,22 +9,21 @@ describe("assembleTransaction", () => {
"GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI"
).toScAddress();

const fnAuth = new SorobanClient.xdr.SorobanAuthorizationEntry({
const fnAuth = new xdr.SorobanAuthorizationEntry({
// Include a credentials w/ a nonce to trigger this
credentials:
new SorobanClient.xdr.SorobanCredentials.sorobanCredentialsAddress(
new SorobanClient.xdr.SorobanAddressCredentials({
address: scAddress,
nonce: new SorobanClient.xdr.Int64(0),
signatureExpirationLedger: 1,
signatureArgs: [],
})
),
credentials: new xdr.SorobanCredentials.sorobanCredentialsAddress(
new xdr.SorobanAddressCredentials({
address: scAddress,
nonce: new xdr.Int64(0),
signatureExpirationLedger: 1,
signatureArgs: [],
})
),
// And a basic invocation
rootInvocation: new SorobanClient.xdr.SorobanAuthorizedInvocation({
rootInvocation: new xdr.SorobanAuthorizedInvocation({
function:
SorobanClient.xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeContractFn(
new SorobanClient.xdr.SorobanAuthorizedContractFunction({
xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeContractFn(
new xdr.SorobanAuthorizedContractFunction({
contractAddress: scAddress,
functionName: "fn",
args: [],
Expand All @@ -32,9 +33,9 @@ describe("assembleTransaction", () => {
}),
});

const sorobanTransactionData = new SorobanClient.xdr.SorobanTransactionData({
resources: new SorobanClient.xdr.SorobanResources({
footprint: new SorobanClient.xdr.LedgerFootprint({
const sorobanTransactionData = new xdr.SorobanTransactionData({
resources: new xdr.SorobanResources({
footprint: new xdr.LedgerFootprint({
readOnly: [],
readWrite: [],
}),
Expand All @@ -43,8 +44,8 @@ describe("assembleTransaction", () => {
writeBytes: 0,
extendedMetaDataSizeBytes: 0,
}),
refundableFee: SorobanClient.xdr.Int64.fromString("0"),
ext: new SorobanClient.xdr.ExtensionPoint(0),
refundableFee: xdr.Int64.fromString("0"),
ext: new xdr.ExtensionPoint(0),
});

const simulationResponse = {
Expand All @@ -54,7 +55,7 @@ describe("assembleTransaction", () => {
results: [
{
auth: [fnAuth.toXDR("base64")],
xdr: SorobanClient.xdr.ScVal.scvU32(0).toXDR().toString("base64"),
xdr: xdr.ScVal.scvU32(0).toXDR().toString("base64"),
},
],
latestLedger: 3,
Expand All @@ -78,9 +79,7 @@ describe("assembleTransaction", () => {
})
.addOperation(
SorobanClient.Operation.invokeHostFunction({
func: new SorobanClient.xdr.HostFunction.hostFunctionTypeInvokeContract(
[]
),
func: new xdr.HostFunction.hostFunctionTypeInvokeContract([]),
auth: [],
})
)
Expand Down Expand Up @@ -171,7 +170,7 @@ describe("assembleTransaction", () => {
).to.have.length(0);
});

it("throws for non-invokehost-fn ops", () => {
it("throws for non-Soroban ops", () => {
const txn = new SorobanClient.TransactionBuilder(source, {
fee: 100,
networkPassphrase,
Expand All @@ -185,7 +184,7 @@ describe("assembleTransaction", () => {
.setTimeout(SorobanClient.TimeoutInfinite)
.build();

try {
expect(() => {
SorobanClient.assembleTransaction(txn, networkPassphrase, {
transactionData: {},
events: [],
Expand All @@ -194,9 +193,35 @@ describe("assembleTransaction", () => {
latestLedger: 3,
});
expect.fail();
} catch (err) {
expect(err.toString()).to.match(/TypeError: unsupported transaction/i);
}
}).to.throw(/unsupported transaction/i);
});

it("works for all Soroban ops", function () {
[
SorobanClient.Operation.invokeHostFunction({
func: xdr.HostFunction.hostFunctionTypeInvokeContract(),
}),
SorobanClient.Operation.bumpFootprintExpiration({
ledgersToExpire: 27,
}),
SorobanClient.Operation.restoreFootprint(),
].forEach((op) => {
const txn = new SorobanClient.TransactionBuilder(source, {
fee: 100,
networkPassphrase,
v1: true,
})
.setTimeout(SorobanClient.TimeoutInfinite)
.addOperation(op)
.build();

const tx = SorobanClient.assembleTransaction(
txn,
networkPassphrase,
simulationResponse
);
expect(tx.operations[0].type).to.equal(op.body().switch().name);
});
});
});
});
Loading

0 comments on commit 2ef1ea2

Please sign in to comment.