This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use @stellar/[email protected] for testnet transactions (#259)
* use latest so we can accept network config in * rm package.lock * add unit tests and fix falsy custom.network logic * add types for mocks
- Loading branch information
Showing
4 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import freighterApi from "@stellar/freighter-api"; | ||
import sinon from "sinon"; | ||
import { TransactionBuilder } from "stellar-sdk"; | ||
import { freighterHandler } from "./freighter"; | ||
|
||
describe("freighterHandler", () => { | ||
const XDR = "foo"; | ||
const NETWORK = "baz"; | ||
const SIGNED_TRANSACTION = "xxx"; | ||
|
||
let freighterApiMock: sinon.SinonMock; | ||
let TransactionBuilderMock: sinon.SinonMock; | ||
beforeEach(() => { | ||
freighterApiMock = sinon.mock(freighterApi); | ||
TransactionBuilderMock = sinon.mock(TransactionBuilder); | ||
}); | ||
afterEach(() => { | ||
freighterApiMock.verify(); | ||
freighterApiMock.restore(); | ||
TransactionBuilderMock.verify(); | ||
TransactionBuilderMock.restore(); | ||
}); | ||
test("signTransaction is called with network", () => { | ||
freighterApiMock | ||
.expects("signTransaction") | ||
.once() | ||
.withArgs(XDR, NETWORK) | ||
.returns(Promise.resolve(SIGNED_TRANSACTION)); | ||
TransactionBuilderMock.expects("fromXDR") | ||
.once() | ||
.withArgs(SIGNED_TRANSACTION) | ||
.returns(true); | ||
|
||
freighterHandler.signTransaction({ | ||
// @ts-ignore | ||
transaction: { toXDR: () => XDR }, | ||
// @ts-ignore | ||
key: { privateKey: "" }, | ||
custom: { network: NETWORK }, | ||
}); | ||
}); | ||
test("signTransaction is called without network", () => { | ||
freighterApiMock | ||
.expects("signTransaction") | ||
.once() | ||
.withArgs(XDR, undefined) | ||
.returns(Promise.resolve(SIGNED_TRANSACTION)); | ||
TransactionBuilderMock.expects("fromXDR") | ||
.once() | ||
.returns(true); | ||
|
||
freighterHandler.signTransaction({ | ||
// @ts-ignore | ||
transaction: { toXDR: () => XDR }, | ||
// @ts-ignore | ||
key: { privateKey: "" }, | ||
}); | ||
}); | ||
test("falsy config is passed as undefined to signTransaction", () => { | ||
freighterApiMock | ||
.expects("signTransaction") | ||
.once() | ||
.withArgs(XDR, undefined) | ||
.returns(Promise.resolve(SIGNED_TRANSACTION)); | ||
TransactionBuilderMock.expects("fromXDR") | ||
.once() | ||
.withArgs(SIGNED_TRANSACTION) | ||
.returns(true); | ||
|
||
freighterHandler.signTransaction({ | ||
// @ts-ignore | ||
transaction: { toXDR: () => XDR }, | ||
// @ts-ignore | ||
key: { privateKey: "" }, | ||
// @ts-ignore | ||
custom: false, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters