Skip to content

Commit

Permalink
wip: testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkoepke committed Aug 15, 2024
1 parent 3cd4645 commit eeff57b
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/core/src/TxBuilders/TxBuilder.Lucid.V1.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ export class TxBuilderLucidV1 extends TxBuilderV1 {
};
}

console.log(secondSwapData.datum);
const datumHash = this.lucid.utils.datumToHash(
secondSwapData.datum as string
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe("TxBuilderLucidV1", () => {
}
});

test("orderRouteSwap() - v1 to v1", async () => {
test.only("orderRouteSwap() - v1 to v1", async () => {
const { build, datum, fees } = await builder.orderRouteSwap({
ownerAddress: PREVIEW_DATA.addresses.current,
swapA: {
Expand Down
13 changes: 10 additions & 3 deletions packages/gummiworm/src/GummiWorm.Lucid.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class GummiWormLucid implements GummiWorm {
};

constructor(public sdk: SundaeSDK) {
const lucid = sdk.builder().lucid;
const lucid = sdk.lucid();
if (!lucid) {
throw new Error(
"A lucid instance is required. Ensure that you have a builder set up in your SDK."
Expand Down Expand Up @@ -119,14 +119,21 @@ export class GummiWormLucid implements GummiWorm {
orderDeposit: this.getParam("minLockAda"),
});

const wallet = this.sdk.builder().lucid.wallet;
const lucid = this.sdk.lucid();
if (!lucid) {
throw new Error(
"Lucid is not available. Are you using a different builder?"
);
}

const wallet = lucid.wallet;
if (!wallet) {
throw new Error(
"A wallet was not initialized in your Lucid instance. Please select a wallet, and then try again."
);
}

const txInstance = this.sdk.builder().lucid.newTx();
const txInstance = lucid.newTx();
const { inline } = this.datumBuilder.buildDepositDatum({
address: depositArgs.address ?? (await wallet.address()),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {
SundaeSDK,
type ITxBuilderFees,
} from "@sundaeswap/core";
import { PREVIEW_DATA, setupLucid } from "@sundaeswap/core/testing";
import { PREVIEW_DATA } from "@sundaeswap/core/testing";
import { C } from "lucid-cardano";

import { setupLucid } from "@sundaeswap/core/lucid";
import { GummiWormLucid } from "../GummiWorm.Lucid.class.js";

let GWInstance: GummiWormLucid;
Expand Down
4 changes: 2 additions & 2 deletions packages/taste-test/src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
MintingPolicy,
OutRef,
SpendingValidator,
UTXO,
UTxO,
} from "lucid-cardano";

/**
Expand Down Expand Up @@ -88,7 +88,7 @@ export interface IBaseArgs {
validator: TScriptType;
};
tasteTestType?: TTasteTestType;
utxos?: UTXO[];
utxos?: UTxO[];
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setupLucid } from "@sundaeswap/core/testing";
import { setupLucid } from "@sundaeswap/core/lucid";
import { Lucid } from "lucid-cardano";

import { TasteTestLucid } from "../classes/TasteTest.Lucid.class.js";
Expand Down
8 changes: 4 additions & 4 deletions packages/taste-test/src/lib/classes/TasteTest.Lucid.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Datum,
Tx,
TxComplete,
UTXO,
UTxO,
fromText,
toUnit,
type Lucid,
Expand Down Expand Up @@ -133,7 +133,7 @@ export class TasteTestLucid implements AbstractTasteTest {

const userKey = await this.getUserKey();

let coveringNode: UTXO | undefined;
let coveringNode: UTxO | undefined;
const nodeUTXOs = await this.lucid.utxosAt(args.validatorAddress);

if (args.utxos) {
Expand Down Expand Up @@ -276,7 +276,7 @@ export class TasteTestLucid implements AbstractTasteTest {
throw new Error("Missing wallet's payment credential hash.");
}

let ownNode: UTXO | undefined;
let ownNode: UTxO | undefined;
if (args.utxos) {
ownNode = args.utxos[0];
} else {
Expand Down Expand Up @@ -506,7 +506,7 @@ export class TasteTestLucid implements AbstractTasteTest {

const userKey = await this.getUserKey();

let ownNode: UTXO | undefined;
let ownNode: UTxO | undefined;
if (args.utxos) {
ownNode = args.utxos[0];
} else {
Expand Down
20 changes: 10 additions & 10 deletions packages/taste-test/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Data, UTXO } from "lucid-cardano";
import { Data, UTxO } from "lucid-cardano";

import { LiquiditySetNode, SetNode } from "./@types/contracts.js";
import { TTasteTestType } from "./@types/index.js";

/**
* Finds the UTxO node that covers a given user key.
*
* @param {UTXO[]} utxos - An array of UTxO objects to search through.
* @param {UTxO[]} utxos - An array of UTxO objects to search through.
* @param {string} userKey - The user key to find the covering node for.
* @param {TTasteTestType} ttType - The type of Taste Test we are using.
* @returns {UTXO|undefined} - The covering UTxO node, or undefined if no covering node is found.
* @returns {UTxO|undefined} - The covering UTxO node, or undefined if no covering node is found.
*
* @example
* const utxos = [...]; // your array of UTxO objects
* const userKey = 'someUserKey';
* const coveringNode = findCoveringNode(utxos, userKey);
*/
export const findCoveringNode = (
utxos: UTXO[],
utxos: UTxO[],
userKey: string,
ttType: TTasteTestType
) =>
Expand All @@ -39,17 +39,17 @@ export const findCoveringNode = (
/**
* Searches through a list of UTXOs to find a node owned by the user, identified by a specific key.
*
* @param {UTXO[]} utxos - An array of unspent transaction outputs (UTXOs).
* @param {UTxO[]} utxos - An array of unspent transaction outputs (UTXOs).
* @param {string} userKey - The unique identifier key for the user, used to find a specific node in the UTXOs.
* @param {TTasteTestType} ttType - The type of Taste Test we are using.
* @returns {UTXO | undefined} - Returns the UTXO that contains the user's node if found, otherwise returns undefined.
* @returns {UTxO | undefined} - Returns the UTXO that contains the user's node if found, otherwise returns undefined.
*
* This function iterates through the provided `utxos`, attempting to match the `userKey` with a key within the datum of each UTXO.
* If a match is found, it indicates that the UTXO belongs to the user's node, and this UTXO is returned.
* If no matching node is found in the list of UTXOs, the function returns undefined, indicating the user's node was not found.
*/
export const findOwnNode = (
utxos: UTXO[],
utxos: UTxO[],
userKey: string,
ttType: TTasteTestType
) =>
Expand All @@ -68,17 +68,17 @@ export const findOwnNode = (
/**
* Searches through a list of UTXOs to find a node owned by the user, identified by a specific key, and return the next reference (previous to the user's node).
*
* @param {UTXO[]} utxos - An array of unspent transaction outputs (UTXOs).
* @param {UTxO[]} utxos - An array of unspent transaction outputs (UTXOs).
* @param {string} userKey - The unique identifier key for the user, used to find a specific node in the UTXOs.
* @param {TTasteTestType} ttType - The type of Taste Test we are using.
* @returns {UTXO | undefined} - Returns the UTXO that contains the previous node of the user's node if found, otherwise returns undefined.
* @returns {UTxO | undefined} - Returns the UTXO that contains the previous node of the user's node if found, otherwise returns undefined.
*
* This function iterates through the provided `utxos`, attempting to match the `userKey` with a key within the datum of each UTXO.
* If a match is found, it indicates that the UTXO belongs to the user's node, and the UTXO referenced as the previous node is returned.
* If no matching node is found in the list of UTXOs, the function returns undefined, indicating the previous node of the user's node was not found.
*/
export const findPrevNode = (
utxos: UTXO[],
utxos: UTxO[],
userKey: string,
ttType: TTasteTestType
) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SundaeUtils } from "@sundaeswap/core/utilities";
import {
Constr,
Data,
UTXO,
UTxO,
type Assets,
type Datum,
type Lucid,
Expand Down Expand Up @@ -337,7 +337,7 @@ export class YieldFarmingLucid implements YieldFarming {
referralFee,
}: {
destination: string;
positions: UTXO[];
positions: UTxO[];
referralFee?: ITxBuilderReferralFee;
}) {
const tx = this.lucid.newTx();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { jest } from "@jest/globals";
import { AssetAmount } from "@sundaeswap/asset";
import { ADA_METADATA } from "@sundaeswap/core";
import { PREVIEW_DATA, setupLucid } from "@sundaeswap/core/testing";
import { setupLucid } from "@sundaeswap/core/lucid";
import { PREVIEW_DATA } from "@sundaeswap/core/testing";
import { C, Data, Lucid, Tx } from "lucid-cardano";

import { Delegation, TDelegation } from "../../../@types/contracts.js";
Expand Down

0 comments on commit eeff57b

Please sign in to comment.