Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __test__/unit/debt_order/debt_order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { Dharma } from "../../../src/dharma";

jest.unmock("@dharmaprotocol/contracts");

import { FILL_SCENARIOS } from "./scenarios/fill_scenarios";
import { IS_EXPIRED_SCENARIOS } from "./scenarios/is_expired_scenarios";
import { DEBT_ORDER_PARAMS_ONE } from "./scenarios/valid_debt_order_params";

// Test runners
import { testCancel } from "./runners/cancel_as_debtor";
import { testCreate } from "./runners/create";
import { testFill } from "./runners/fill";
import { testGetTotalExpectedRepaymentAmount } from "./runners/get_total_expected_repayment_amount";
import { testIsCancelled } from "./runners/is_cancelled";
import { testExpired } from "./runners/is_expired";
Expand All @@ -25,6 +27,12 @@ describe("Debt Order (Integration)", () => {
await testCreate(dharma, DEBT_ORDER_PARAMS_ONE);
});

describe("#fill", async () => {
FILL_SCENARIOS.forEach(async (scenario) => {
await testFill(dharma, web3, scenario);
});
});

describe("#isExpired", async () => {
IS_EXPIRED_SCENARIOS.forEach(async (scenario) => {
await testExpired(dharma, scenario);
Expand Down
48 changes: 48 additions & 0 deletions __test__/unit/debt_order/runners/fill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as Web3 from "web3";

// Types
import { DebtOrder, DebtOrderParams } from "../../../../src/debt_order";
import { EthereumAddress } from "../../../../src/types";

// Import Dharma for typing-checking.
import { Dharma } from "../../../../src";

// Test utils
import { ACCOUNTS } from "../../../accounts";

const CREDITOR = ACCOUNTS[1];

import { FillScenario } from "../scenarios/fill_scenarios";
import { setBalancesAndAllowances } from "../utils/set_balances_and_allowances";

export async function testFill(dharma: Dharma, web3: Web3, scenario: FillScenario) {
await setBalancesAndAllowances(dharma, web3, scenario.debtOrderParams, CREDITOR.address);

describe(scenario.description, () => {
let debtOrder: DebtOrder;

beforeAll(async () => {
debtOrder = await DebtOrder.create(dharma, scenario.debtOrderParams);
scenario.setUpDebtOrder(debtOrder);
});

if (scenario.shouldSucceed) {
test.only("#fill succeeds", async () => {
const fillTransactionHash = await debtOrder.fillAsCreditor(
scenario.creditorAddress,
);

await dharma.blockchain.awaitTransactionMinedAsync(fillTransactionHash);
// test the transaction receipt is correct
});
} else {
test("#fill fails", async () => {
const fillTransactionHash = await debtOrder.fillAsCreditor(
scenario.creditorAddress,
);

// test the transaction fails
});
}
});
}
49 changes: 49 additions & 0 deletions __test__/unit/debt_order/scenarios/fill_scenarios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Debt Order
import { DebtOrder, DebtOrderParams } from "../../../../src/debt_order";

// Types
import { EthereumAddress, InterestRate, TimeInterval, TokenAmount } from "../../../../src/types";

// Test utils
import { ACCOUNTS } from "../../../accounts";

const debtor = ACCOUNTS[1];
const creditor = ACCOUNTS[2];

export interface FillScenario {
description: string;
creditorAddress: EthereumAddress;
debtOrderParams: DebtOrderParams;
setUpDebtOrder: (debtOrder: DebtOrder) => void;
shouldSucceed: boolean;
}

const creditorAddress: EthereumAddress = new EthereumAddress(creditor.address);

const debtOrderParams: DebtOrderParams = {
principal: new TokenAmount(5, "REP"),
collateral: new TokenAmount(10, "WETH"),
interestRate: new InterestRate(12.3),
termLength: new TimeInterval(6, "months"),
debtorAddress: new EthereumAddress(debtor.address),
expiresIn: new TimeInterval(5, "days"),
};

export const FILL_SCENARIOS: FillScenario[] = [
{
description: "when the debt order is open",
creditorAddress,
debtOrderParams,
setUpDebtOrder: (debtOrder: DebtOrder) => {},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block is empty

shouldSucceed: true,
},
// {
// description: "when the debt order is expired",
// },
// {
// description: "when the debt order is already filled",
// },
// {
// description: "when the debt order is canceled",
// },
];
11 changes: 0 additions & 11 deletions src/apis/order_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,6 @@ export class OrderAPI {

const debtOrderDataWrapped = new DebtOrderDataWrapper(debtOrderData);

console.log(
debtOrderDataWrapped.getCreditor(),
debtOrderDataWrapped.getOrderAddresses(),
debtOrderDataWrapped.getOrderValues(),
debtOrderDataWrapped.getOrderBytes32(),
debtOrderDataWrapped.getSignaturesV(),
debtOrderDataWrapped.getSignaturesR(),
debtOrderDataWrapped.getSignaturesS(),
txOptions,
);

return debtKernel.fillDebtOrder.sendTransactionAsync(
debtOrderDataWrapped.getCreditor(),
debtOrderDataWrapped.getOrderAddresses(),
Expand Down