Skip to content

Commit

Permalink
Merge branch 'tests/tx-test-cases' into fix-versions-bump
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Aug 30, 2024
2 parents 721a317 + 3665325 commit 8966d55
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions packages/mesh-transaction/test/transaction/sendAssets.test.ts
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",
);
});
});

0 comments on commit 8966d55

Please sign in to comment.