OxL Reference

tests/transfer_test.oxl

oxl
use super.bank { Bank, Account, transfer, Insufficient, Blocked, CLOSED_ACCOUNT }

test "a transfer moves the money" {
  Account(10).fund(100)!
  assert_eq(transfer(10, 11, 30)!, 30)
  assert_eq(Bank.balance(10)!, 70)
  assert_eq(Bank.balance(11)!, 30)
}

test "a failed credit compensates the debit" {
  Account(20).fund(100)!
  let r = transfer(20, CLOSED_ACCOUNT, 50)
  assert r is Blocked
  assert_eq(Bank.balance(20)!, 100)
}

test "insufficient funds stop the saga before anything is credited" {
  Account(30).fund(10)!
  assert transfer(30, 31, 500) is Insufficient
  assert_eq(Bank.balance(30)!, 10)
  assert_eq(Bank.balance(31)!, 0)
}

Source: examples/bank-saga/tests/transfer_test.oxl