-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding test case for txbuilder compelte
- Loading branch information
1 parent
3ddd8a2
commit 034b545
Showing
2 changed files
with
106 additions
and
12 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
116 changes: 105 additions & 11 deletions
116
packages/mesh-transaction/test/mesh-tx-builder/complete.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 |
---|---|---|
@@ -1,14 +1,108 @@ | ||
// jest.mock("@meshsdk/transaction", () => ({ | ||
// resolveDataHash: jest.fn(), | ||
// })); | ||
|
||
describe("complete", () => { | ||
describe("fetcher", () => { | ||
it("should fill incomplete tx in", () => { | ||
expect(1).toBe(1); | ||
import { | ||
AccountInfo, | ||
emptyTxBuilderBody, | ||
IFetcher, | ||
MintItem, | ||
ScriptSource, | ||
SimpleScriptSourceInfo, | ||
TransactionInfo, | ||
TxIn, | ||
} from "@meshsdk/common"; | ||
import { MeshTxBuilder } from "@meshsdk/transaction"; | ||
|
||
class MockTxBuilder extends MeshTxBuilder { | ||
constructor() { | ||
super(); | ||
this.queriedTxHashes = new Set(); | ||
this.queriedUTxOs = {}; | ||
this.fetcher = { | ||
fetchUTxOs: jest.fn().mockResolvedValue([]), | ||
fetchAccountInfo: jest.fn().mockResolvedValue({} as AccountInfo), | ||
fetchAddressUTxOs: jest.fn().mockResolvedValue([]), | ||
fetchProtocolParameters: jest.fn().mockResolvedValue({}), | ||
fetchTxInfo: jest.fn().mockResolvedValue({} as TransactionInfo), | ||
fetchNetworkInfo: jest.fn().mockResolvedValue({}), | ||
fetchAssetInfo: jest.fn().mockResolvedValue({}), | ||
fetchStakePoolInfo: jest.fn().mockResolvedValue({}), | ||
fetchDelegationInfo: jest.fn().mockResolvedValue({}), | ||
} as unknown as IFetcher; | ||
} | ||
|
||
getUTxOInfoExtended = this.getUTxOInfo; | ||
queryAllTxInfoExtended = this.queryAllTxInfo; | ||
} | ||
|
||
describe("MeshTxBuilder", () => { | ||
let txBuilder: MockTxBuilder; | ||
|
||
beforeEach(() => { | ||
txBuilder = new MockTxBuilder(); | ||
}); | ||
|
||
it("should update incomplete txIns and mints", async () => { | ||
// Mock methods | ||
|
||
jest | ||
.spyOn(txBuilder.serializer as any, "serializeTxBody") | ||
.mockImplementation(() => ""); | ||
jest | ||
.spyOn(txBuilder as any, "addUtxosFromSelection") | ||
.mockImplementation(() => {}); | ||
jest | ||
.spyOn(txBuilder as any, "isInputComplete") | ||
.mockImplementation((txIn) => false); | ||
jest | ||
.spyOn(txBuilder as any, "isMintComplete") | ||
.mockImplementation((mint) => false); | ||
jest.spyOn(txBuilder as any, "queryAllTxInfo").mockResolvedValue(undefined); | ||
const completeTxInformationMock = jest | ||
.spyOn(txBuilder as any, "completeTxInformation") | ||
.mockImplementation(() => {}); | ||
const completeScriptInfoMock = jest | ||
.spyOn(txBuilder as any, "completeScriptInfo") | ||
.mockImplementation(() => {}); | ||
|
||
// Define incomplete inputs and mints | ||
const incompleteTxIns: TxIn[] = [ | ||
{ type: "PubKey", txIn: { txHash: "txHash1", txIndex: 0 } }, | ||
{ type: "PubKey", txIn: { txHash: "txHash2", txIndex: 1 } }, | ||
]; | ||
const incompleteMints: MintItem[] = [ | ||
{ | ||
type: "Plutus", | ||
policyId: "policyId1", | ||
assetName: "assetName1", | ||
amount: "100", | ||
scriptSource: { | ||
type: "Inline", | ||
txHash: "txHash3", | ||
txIndex: 2, | ||
} as ScriptSource, | ||
}, | ||
]; | ||
|
||
// Set the meshTxBuilderBody | ||
txBuilder.meshTxBuilderBody = { | ||
...emptyTxBuilderBody(), | ||
inputs: incompleteTxIns, | ||
collaterals: [], | ||
mints: incompleteMints, | ||
}; | ||
|
||
// Call the complete method | ||
await txBuilder.complete(); | ||
|
||
// Assertions | ||
expect(completeTxInformationMock).toHaveBeenCalledTimes( | ||
incompleteTxIns.length, | ||
); | ||
incompleteTxIns.forEach((txIn) => { | ||
expect(completeTxInformationMock).toHaveBeenCalledWith(txIn); | ||
}); | ||
// it("should fill incomplete collateral tx in", () => {}); | ||
// it("should fill script tx in ref script script hash", () => {}); | ||
// it("should fill plutus minting ref script script hash", () => {}); | ||
|
||
expect(completeScriptInfoMock).toHaveBeenCalledTimes(1); | ||
expect(completeScriptInfoMock).toHaveBeenCalledWith( | ||
(incompleteMints[0] as any).scriptSource, | ||
); | ||
}); | ||
}); |