Skip to content

test(sdk): add cross-contract integration tests and Friendbot faucet script - #136

Open
Majormaxx wants to merge 5 commits into
xqcxx:mainfrom
Majormaxx:test/69-72-integration-tests-testnet-faucet
Open

Majormaxx wants to merge 5 commits into
xqcxx:mainfrom
Majormaxx:test/69-72-integration-tests-testnet-faucet

Conversation

@Majormaxx

@Majormaxx Majormaxx commented Nov 26, 2026 •

Copy link
Copy Markdown

Summary

Adds a cross-contract integration test crate (TL-7) and a Friendbot funding script with test token setup (TL-10). Writing the integration tests exposed a payroll bug on main, which is fixed here as well because the Rust CI job cannot pass without it.

Fix: payroll stream on main

main currently fails cargo test --all. The merge in 4535c5d left payroll_stream/src/test.rs with duplicate helper functions, duplicate create_stream calls and references to undefined variables, so the crate does not compile its tests. The same merge also duplicated two token transfers in payroll_stream/src/lib.rs:

Function Before After
create_stream pulls 2 * total_amount from the sender after checking only total_amount pulls total_amount once
claim pays the recipient 2 * claimable pays claimable once

I removed the duplicated transfers and the leftover merge lines in test.rs. No test was dropped; all 22 payroll tests run and pass. The regenerated payroll snapshots reflect the single transfer.

Fix: build on current stable Rust

CI installs the latest stable toolchain (rustc 1.100.0), and ethnum 1.5.2, which soroban-sdk pulls in, no longer compiles there (E0512: cannot transmute between types of different sizes). This breaks every Rust and Docs job. Cargo.lock now pins ethnum 1.5.3, which builds. I reproduced the failure and the fix locally on 1.100.0.

TL-7: contracts/integration_tests

New workspace member with only a tests/ target, so it adds nothing to the release or wasm builds. Each test registers the real treasury, governance, payroll stream and vesting contracts plus a Stellar Asset Contract token in one Env. No contract is mocked.

To reach the shared types from outside their crates, errors and types are now pub mod in each contract's lib.rs.

Test Flow
approved_proposal_is_disbursed_by_treasury_multisig 3 members vote on a budget, the proposal is finalized, the treasury pays it out through a 2-of-3 withdrawal, and governance marks it executed. Also checks that a single approval cannot execute and that a paid withdrawal cannot be paid again
rejected_proposal_cannot_be_executed_and_funds_stay_in_treasury A voted-down budget cannot be executed and the vault balance does not change
treasury_budget_funds_payroll_stream_claimed_by_employee Treasury pays an employer, the employer opens a stream, the employee claims at 25%, 75% and after the end, and the stream ends Completed with the payroll contract empty
treasury_budget_funds_vesting_schedule_claimed_by_beneficiary Treasury pays a grantor, who funds a cliff plus linear schedule. Claims fail before the cliff, then return the cliff unlock, the linear half, and the rest
multiple_users_share_payroll_and_vesting_without_leaking_funds One operator runs two streams and two schedules. Users cannot claim each other's funds, one stream is cancelled and one grant revoked midway, and the sum of all balances equals the amount minted

The treasury deposit entrypoint in the workspace contract does not transfer tokens yet, so the tests fund the vault with a direct token transfer. With the duplicate transfers put back, the payroll and multi-user tests fail.

TL-10: scripts/fund-testnet.sh

./scripts/fund-testnet.sh                       # orbitpay-admin, -employer, -employee-1, -employee-2
./scripts/fund-testnet.sh alice bob carol       # your own account names
./scripts/fund-testnet.sh --token OPAY          # also deploy a test token and mint to each account
./scripts/fund-testnet.sh --token OPAY --amount 50000000000
  • Creates any missing accounts as stellar CLI identities. Secret keys stay in the CLI keystore and are never written to the repo.
  • Funds every account through https://friendbot.stellar.org and prints the funding transaction hash. Accounts that already hold the starting balance are skipped.
  • With --token, the first account issues the asset. The script deploys its Stellar Asset Contract (or reuses the existing one), adds trustlines on the other accounts and mints --amount to each of them.
  • Same style as scripts/deploy.sh. Usage is documented in a new "Testnet Setup" section in CONTRIBUTING.md.

The TL-7 and TL-10 boxes in docs/ISSUES-SDK-TOOLING.md are checked.

Testing

cd contracts
cargo test --all
  governance         10 passed
  integration_tests   5 passed
  payroll_stream     22 passed
  treasury           16 passed
  vesting            18 passed
cargo build --release --all                               ok
cargo build --target wasm32-unknown-unknown --release     ok
cargo doc --no-deps --all                                 ok

All of the above pass on rustc 1.96.0 and 1.100.0.

I ran the faucet script end to end against testnet:

  • Funded GDQ3XX7SWE26LNWKDDLZRP6ZJ5WLR547WDI6C5RJCN7QMIA7PASTIF33 (tx cb5c81efe6bce178e845191d3d8e142ffbd46fbb16acdf511eed5e17cf906787), GB5U43HH7E4N5FWGVK5RHR7YIOSD5JP535WWH4T2SYIDAF2EJW66XBRQ (tx bae2ec9598479826075cc2d712b438cfc357b17a80371f485079e5067237a7f5) and GCGJCZKNUSY2VMIGQOVHB6XNEOQA5DXHNTUW4X554XOJ6D4QUQXRTYKC (tx 1da5c63f23853dce931c3020a73c3e5858ebac95057a9dbb209db2ca105a1860)
  • Deployed the OPAY test token at CBTC4VANAMZP3UBTDSELYVK7MHB3E6NSVZOUGPJJROK3YFNP2DL7RF47 and minted to both non-issuer accounts (tx ea47f9fa07776a495d3fe6900a643be0a36a774f569cc95c6a51334f5b67709f, 317b2252ccb45c775f06ff4081987435cab6b6446ebd35e4db89a187c825efb5)
  • Re-running skips funded accounts, reuses the token contract and mints again

I also checked the payroll fix on testnet with that token. I deployed payroll_stream at CBVI6JGB3TGIYJODSA63NEATD3J3OJFDJJGCPDMTM5OPRIXX5UWHIEUJ and streamed 6000 to the employee. create_stream took exactly 6000 from the employer (tx bb409a44d61a774c810b1588bb74d07cbabef55f614f16c41f5b36c52d3831e2). After the stream ended, claim paid exactly 6000 and left the contract at 0 (tx f8b8758365462e54385b4058c40d7523bef97f9febc079b505d2574c1664824a).

One thing outside this PR: on Rust 1.96, testnet rejects a wasm32-unknown-unknown build at upload with Error(WasmVm, InvalidAction). That is the target scripts/deploy.sh uses. For the deploy above I built with stellar contract build, which targets wasm32v1-none. I can open a separate issue for deploy.sh if you'd like.

Closes #69
Closes #72

@Majormaxx

Copy link
Copy Markdown
Author

Reviewer note: the payroll fix in 8390132 is separate from the TL-7/TL-10 work, so it can be reviewed on its own. main doesn't compile the payroll tests today, and without that fix Rust CI on this PR would fail for reasons unrelated to it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TL-10: Testnet Faucet Integration TL-7: Contract Integration Tests

1 participant