Skip to content

Commit

Permalink
Fix a bug in assembleTransaction (#57)
Browse files Browse the repository at this point in the history
* Fix a bug in assembleTransaction

* Add regression test

* Add basic test for non-invokeHostFunction ops
  • Loading branch information
Paul Bellamy committed Mar 3, 2023
1 parent 59c9638 commit 0c43263
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export function assembleTransaction(
if (!sim) {
throw new Error("missing simulated operation");
}
let footprint = sim.footprint;
let footprint = sim.footprint ?? rawOp.footprint;
if (!(footprint instanceof xdr.LedgerFootprint)) {
footprint = xdr.LedgerFootprint.fromXDR(footprint.toString(), "base64");
}
const auth = sim.auth.map((a) =>
const auth = (sim.auth ?? rawOp.auth).map((a) =>
a instanceof xdr.ContractAuth
? a
: xdr.ContractAuth.fromXDR(a.toString(), "base64"),
Expand Down
32 changes: 32 additions & 0 deletions test/unit/transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,37 @@ describe("assembleTransaction", () => {

expect(result.operations[0].auth.length).to.equal(1);
});

it("throws for non-invokehost-fn ops", () => {
const txn = new SorobanClient.TransactionBuilder(source, {
fee: 100,
networkPassphrase,
v1: true,
})
.addOperation(
SorobanClient.Operation.changeTrust({
asset: SorobanClient.Asset.native(),
}),
)
.setTimeout(SorobanClient.TimeoutInfinite)
.build();

try {
SorobanClient.assembleTransaction(txn, networkPassphrase, [null]);
expect.fail();
} catch (err) {
expect(err.toString()).to.equal("Error: Unsupported operation type");
}
});

it("handles transactions with no auth or footprint", () => {
const txn = emptyTransaction();

const result = SorobanClient.assembleTransaction(txn, networkPassphrase, [
{},
]);

expect(result.operations[0].auth.length).to.equal(0);
});
});
});

0 comments on commit 0c43263

Please sign in to comment.