diff --git a/README.md b/README.md index 07be3ea..e648769 100644 --- a/README.md +++ b/README.md @@ -363,11 +363,10 @@ stepwise withdrawal, partial withdrawal and its over-request and non-positive guards, cliff gating, cancellation splits, the `locked` and `progress` views across a stream's life, the cliff and no-cliff schedules documented above, authorization requirements, invalid input, past and -boundary time-window rejection, backdated-start acceptance, multiple -recipients funded by one sender, id-counter exhaustion at the `u64::MAX` -boundary, rejection of the contract's own address in each participant role, -self-streams, the documented precedence between validation groups, and -double-withdraw and unknown-id guards. +boundary time-window rejection, backdated-start acceptance, multiple token +parallel streams, id-counter exhaustion at the `u64::MAX` boundary, rejection +of the contract's own address in each participant role, self-streams, the +documented precedence between validation groups, and double-withdraw and unknown-id guards. It also covers the storage and event behaviour described above: the order in which each entry point moves tokens and publishes its event, the Created, diff --git a/contracts/stream/src/test.rs b/contracts/stream/src/test.rs index 4bac24c..f23eeb6 100644 --- a/contracts/stream/src/test.rs +++ b/contracts/stream/src/test.rs @@ -245,25 +245,30 @@ fn create_stream_locks_funds_and_assigns_id() { } #[test] -fn one_sender_can_stream_to_multiple_recipients() { - let t = StreamTest::setup(1_500); - let second_recipient = Address::generate(&t.env); +fn one_sender_can_stream_multiple_tokens_in_parallel() { + let t = StreamTest::setup(1_000); + let second_issuer = Address::generate(&t.env); + let second_sac = t.env.register_stellar_asset_contract_v2(second_issuer); + let second_token_address = second_sac.address(); + let second_token = token::TokenClient::new(&t.env, &second_token_address); + let second_token_admin = token::StellarAssetClient::new(&t.env, &second_token_address); + second_token_admin.mint(&t.sender, &2_000); t.set_time(100); let first_id = t.contract.create_stream( &t.sender, &t.recipient, &t.token_address, - &500, + &400, &100, &1_100, &100, ); let second_id = t.contract.create_stream( &t.sender, - &second_recipient, - &t.token_address, - &700, + &t.recipient, + &second_token_address, + &900, &100, &1_100, &100, @@ -272,32 +277,30 @@ fn one_sender_can_stream_to_multiple_recipients() { assert_eq!(first_id, 0); assert_eq!(second_id, 1); assert_eq!(t.contract.stream_count(), 2); - assert_eq!(t.token.balance(&t.sender), 300); - assert_eq!(t.token.balance(&t.contract.address), 1_200); - assert_eq!(t.token.balance(&t.recipient), 0); - assert_eq!(t.token.balance(&second_recipient), 0); + assert_eq!(t.token.balance(&t.sender), 600); + assert_eq!(second_token.balance(&t.sender), 1_100); + assert_eq!(t.token.balance(&t.contract.address), 400); + assert_eq!(second_token.balance(&t.contract.address), 900); let first = t.contract.get_stream(&first_id); - assert_eq!(first.sender, t.sender); - assert_eq!(first.recipient, t.recipient); - assert_eq!(first.total_amount, 500); + assert_eq!(first.token, t.token_address); + assert_eq!(first.total_amount, 400); assert_eq!(first.withdrawn, 0); let second = t.contract.get_stream(&second_id); - assert_eq!(second.sender, t.sender); - assert_eq!(second.recipient, second_recipient); - assert_eq!(second.total_amount, 700); + assert_eq!(second.token, second_token_address); + assert_eq!(second.total_amount, 900); assert_eq!(second.withdrawn, 0); t.set_time(600); - assert_eq!(t.contract.withdraw(&first_id), 250); - assert_eq!(t.contract.withdraw(&second_id), 350); - assert_eq!(t.token.balance(&t.recipient), 250); - assert_eq!(t.token.balance(&second_recipient), 350); - assert_eq!(t.token.balance(&t.contract.address), 600); - - assert_eq!(t.contract.get_stream(&first_id).withdrawn, 250); - assert_eq!(t.contract.get_stream(&second_id).withdrawn, 350); + assert_eq!(t.contract.withdraw(&first_id), 200); + assert_eq!(t.contract.withdraw(&second_id), 450); + assert_eq!(t.token.balance(&t.recipient), 200); + assert_eq!(second_token.balance(&t.recipient), 450); + assert_eq!(t.token.balance(&t.contract.address), 200); + assert_eq!(second_token.balance(&t.contract.address), 450); + assert_eq!(t.contract.get_stream(&first_id).withdrawn, 200); + assert_eq!(t.contract.get_stream(&second_id).withdrawn, 450); } #[test]