-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tests/tx-test-cases' into fix-versions-bump
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
packages/mesh-transaction/test/transaction/sendAssets.test.ts
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,84 @@ | ||
import { Asset, Recipient } from "@meshsdk/common"; | ||
import { MeshTxBuilder, Transaction } from "@meshsdk/transaction"; | ||
import { MeshWallet } from "@meshsdk/wallet"; | ||
|
||
jest.mock("@meshsdk/transaction", () => { | ||
const txBuilderMock = { | ||
txOut: jest.fn(), | ||
txOutDatumHashValue: jest.fn(), | ||
txOutInlineDatumValue: jest.fn(), | ||
}; | ||
|
||
return { | ||
MeshTxBuilder: jest.fn(() => txBuilderMock), | ||
Transaction: jest.requireActual("@meshsdk/transaction").Transaction, | ||
}; | ||
}); | ||
|
||
describe("Transaction", () => { | ||
let wallet: MeshWallet; | ||
let transaction: Transaction; | ||
let txBuilderMock: jest.Mocked<MeshTxBuilder>; | ||
|
||
beforeEach(() => { | ||
wallet = new MeshWallet({ | ||
key: { | ||
type: "mnemonic", | ||
words: MeshWallet.brew() as string[], | ||
}, | ||
networkId: 0, | ||
}); | ||
txBuilderMock = new MeshTxBuilder({}) as jest.Mocked<MeshTxBuilder>; | ||
transaction = new Transaction({ | ||
initiator: wallet, | ||
}); | ||
transaction.txBuilder = txBuilderMock; | ||
}); | ||
|
||
it("should trigger txOutDatumHashValue when recipient has datum with inline set to false", () => { | ||
const address = wallet.getUsedAddresses()[0]; | ||
const recipient: Recipient = { | ||
address: address as string, | ||
datum: { | ||
inline: false, | ||
value: "datum-value", | ||
}, | ||
}; | ||
const assets: Asset[] = [ | ||
{ | ||
unit: "lovelace", | ||
quantity: "1000", | ||
}, | ||
]; | ||
|
||
transaction.sendAssets(recipient, assets); | ||
|
||
expect(txBuilderMock.txOut).toHaveBeenCalledWith(address, assets); | ||
expect(txBuilderMock.txOutDatumHashValue).toHaveBeenCalledWith( | ||
"datum-value", | ||
); | ||
}); | ||
it("should trigger txOutInlineDatumValue when recipient has datum with inline set to false", () => { | ||
const address = wallet.getUsedAddresses()[0]; | ||
const recipient: Recipient = { | ||
address: address as string, | ||
datum: { | ||
inline: true, | ||
value: "datum-value", | ||
}, | ||
}; | ||
const assets: Asset[] = [ | ||
{ | ||
unit: "lovelace", | ||
quantity: "1000", | ||
}, | ||
]; | ||
|
||
transaction.sendAssets(recipient, assets); | ||
|
||
expect(txBuilderMock.txOut).toHaveBeenCalledWith(address, assets); | ||
expect(txBuilderMock.txOutInlineDatumValue).toHaveBeenCalledWith( | ||
"datum-value", | ||
); | ||
}); | ||
}); |