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");
});
});
4 changes: 4 additions & 0 deletions contracts/splitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ impl Splitter {
load(&env, id)
}

pub fn is_locked(env: Env, id: u64) -> Result<bool, Error> {
Ok(load(&env, id)?.controller.is_none())
}

pub fn recipient_count(env: Env, id: u64) -> Result<u32, Error> {
Ok(load(&env, id)?.recipients.len())
}
Expand Down
25 changes: 25 additions & 0 deletions contracts/splitter/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1923,3 +1923,28 @@ fn single_recipient_gets_full_amount() {
assert_eq!(token_client.balance(&a), amount);
assert_eq!(token_client.balance(&payer), 0);
}

#[test]
fn is_locked_works() {
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_mutable = s.client.create_split(
&creator,
&vec![&s.env, acct(&a), acct(&b)],
&vec![&s.env, 5_000, 5_000],
&Some(controller.clone()),
);
assert!(!s.client.is_locked(&id_mutable));

let id_locked = s.client.create_split(
&creator,
&vec![&s.env, acct(&a), acct(&b)],
&vec![&s.env, 5_000, 5_000],
&None,
);
assert!(s.client.is_locked(&id_locked));
}