diff --git a/app/src/lib/tributary.test.ts b/app/src/lib/tributary.test.ts index ec2522d..90d2442 100644 --- a/app/src/lib/tributary.test.ts +++ b/app/src/lib/tributary.test.ts @@ -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, @@ -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"); - }); -}); diff --git a/contracts/splitter/src/lib.rs b/contracts/splitter/src/lib.rs index 6388a7f..89d2ecb 100644 --- a/contracts/splitter/src/lib.rs +++ b/contracts/splitter/src/lib.rs @@ -594,6 +594,10 @@ impl Splitter { load(&env, id) } + pub fn is_locked(env: Env, id: u64) -> Result { + Ok(load(&env, id)?.controller.is_none()) + } + pub fn recipient_count(env: Env, id: u64) -> Result { Ok(load(&env, id)?.recipients.len()) } diff --git a/contracts/splitter/src/test.rs b/contracts/splitter/src/test.rs index 2533347..c0a71d3 100644 --- a/contracts/splitter/src/test.rs +++ b/contracts/splitter/src/test.rs @@ -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)); +}