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
40 changes: 0 additions & 40 deletions app/src/lib/tributary.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import { describe, it, expect } from "vitest";
import {
toStroops,
fromStroops,
formatAmount,
shortAddress,
recipientLabel,
ConversionError,
} from "./tributary";
import { describe, expect, it } from "vitest";
import {
ConversionError,
Expand Down Expand Up @@ -296,35 +287,4 @@ describe("Token conversion functions", () => {
});
});

describe("formatAmount", () => {
it("formats valid decimal string with commas", () => {
expect(formatAmount("1000")).toBe("1,000");
});

it("returns input string if non-numeric", () => {
expect(formatAmount("abc")).toBe("abc");
});
});

describe("shortAddress", () => {
it("shortens stellar address", () => {
expect(
shortAddress("GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFXYFTRE65OTHVRWPAHV7")
).toBe("GBRP…AHV7");
});
});

describe("recipientLabel", () => {
it("formats account recipient", () => {
expect(
recipientLabel({
tag: "Account",
values: ["GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFXYFTRE65OTHVRWPAHV7"],
})
).toBe("GBRP…AHV7");
});

it("formats split recipient", () => {
expect(recipientLabel({ tag: "Split", values: [42n] })).toBe("split #42");
});
});
43 changes: 43 additions & 0 deletions contracts/splitter/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1923,3 +1923,46 @@ fn single_recipient_gets_full_amount() {
assert_eq!(token_client.balance(&a), amount);
assert_eq!(token_client.balance(&payer), 0);
}

#[test]
fn distribute_uses_updated_table_after_update_split() {
let s = setup();
let creator = Address::generate(&s.env);
let a = Address::generate(&s.env);
let b = Address::generate(&s.env);
let controller = Address::generate(&s.env);

let id = s.client.create_split(
&creator,
&vec![&s.env, acct(&a)],
&vec![&s.env, 10_000],
&Some(controller.clone()),
);

let token_id = s
.env
.register_stellar_asset_contract_v2(Address::generate(&s.env));
let token_client = token::Client::new(&s.env, &token_id.address());
let token_admin = token::StellarAssetClient::new(&s.env, &token_id.address());
let payer = Address::generate(&s.env);
let amount = 10_000_000;
token_admin.mint(&payer, &amount);

// Update the routing table
s.client.update_split(
&id,
&vec![&s.env, acct(&a), acct(&b)],
&vec![&s.env, 5_000, 5_000],
);

// Deposit
s.client.deposit(&payer, &id, &token_id, &amount);

// Distribute
s.client.distribute(&id, &token_id);

// Should pay by the NEW routing table
assert_eq!(token_client.balance(&a), amount / 2);
assert_eq!(token_client.balance(&b), amount / 2);
assert_eq!(token_client.balance(&payer), 0);
}