Skip to content

Commit

Permalink
Pull order examples into examples folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Dec 9, 2023
1 parent 8c9b264 commit 102614a
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 119 deletions.
95 changes: 95 additions & 0 deletions lib/tests/examples/ex_order.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use aiken/cbor
use types/order.{Destination, OrderDatum, Swap, Deposit, Withdrawal, Scoop, Cancel}
use aiken/transaction.{NoDatum}
use sundae/multisig
use tests/examples/ex_shared.{print_example, wallet_address}

fn mk_swap() -> OrderDatum {
let addr = wallet_address(#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513")
let dest = Destination { address: addr, datum: NoDatum }
let swap =
Swap(
(#"", #"", 10000000),
(
#"d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf",
#"44554d4d59",
0,
),
)
OrderDatum {
pool_ident: None,
owner: multisig.Signature(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
max_protocol_fee: 2500000,
destination: dest,
details: swap,
extension: Void,
}
}

test example_swap() {
print_example(mk_swap())
}

fn mk_deposit() -> OrderDatum {
let addr = wallet_address(#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513")
let dest = Destination { address: addr, datum: NoDatum }
let deposit =
Deposit((
(#"", #"", 10000000),
(
#"d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf",
#"44554d4d59",
10000000,
),
))
OrderDatum {
pool_ident: None,
owner: multisig.Signature(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
max_protocol_fee: 2500000,
destination: dest,
details: deposit,
extension: Void,
}
}

test example_deposit() {
print_example(mk_deposit())
}

fn mk_withdrawal() {
let addr = wallet_address(#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513")
let dest = Destination { address: addr, datum: NoDatum }
let withdrawal =
Withdrawal(
(
#"d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf",
#"6c",
10000000
),
)
OrderDatum {
pool_ident: None,
owner: multisig.Signature(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
max_protocol_fee: 2500000,
destination: dest,
details: withdrawal,
extension: Void,
}
}

test example_withdrawal() {
print_example(mk_withdrawal())
}

test example_cancel_redeemer() {
print_example(cbor.serialise(Cancel))
}
test example_scoop_redeemer() {
print_example(cbor.serialise(Scoop))
}
42 changes: 38 additions & 4 deletions lib/tests/examples/ex_settings.ak
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use aiken/bytearray
use aiken/transaction/credential.{Address, VerificationKeyCredential}
use aiken/cbor
use sundae/multisig
use aiken/transaction/value
use types/settings.{SettingsDatum}
use aiken/transaction.{Input, Output, InlineDatum}
use tests/examples/ex_shared.{script_address, mk_output_reference}
use tests/examples/ex_shared.{print_example, script_address, mk_output_reference}

pub fn mk_valid_settings_datum(
scoopers: List<ByteArray>,
Expand Down Expand Up @@ -66,10 +65,45 @@ pub fn mk_valid_settings_input(
}

test example_settings_datum() {
trace bytearray.to_hex(
print_example(
cbor.serialise(mk_valid_settings_datum([
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad",
])),
)
True
}

test example_big_settings_datum() {
// 30 scoopers at least
print_example(mk_valid_settings_datum([
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02400",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02401",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02402",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02403",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02404",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02405",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02406",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02407",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02408",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02409",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02410",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02411",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02412",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02413",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02414",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02415",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02416",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02417",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02418",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02419",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02421",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02422",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02423",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02424",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02425",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02426",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02427",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02428",
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa02429",
])
)
}
11 changes: 11 additions & 0 deletions lib/tests/examples/ex_shared.ak
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
use aiken/bytearray
use aiken/cbor
use aiken/transaction.{OutputReference, TransactionId}
use aiken/transaction/credential.{Address, ScriptCredential, VerificationKeyCredential}

pub const examples_enabled: Int = 0
pub fn print_example(d: Data) -> Bool {
if examples_enabled == 1 {
trace bytearray.to_hex(cbor.serialise(d))
True
} else {
True
}
}

pub fn mk_tx_hash(n: Int) -> TransactionId {
expect n < 256
let h =
Expand Down
118 changes: 3 additions & 115 deletions lib/types/order.ak
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use aiken/bytearray
use aiken/cbor
use aiken/transaction.{Datum, NoDatum, OutputReference, ValidityRange}
use aiken/transaction/credential.{Address, VerificationKey, VerificationKeyCredential, Signature}
use aiken/transaction.{Datum, OutputReference, ValidityRange}
use aiken/transaction/credential.{Address, VerificationKey, Signature}
use shared.{Ident, SingletonValue}
use sundae/multisig.{MultisigScript}

Expand All @@ -21,111 +19,6 @@ pub type OrderDatum {
extension: Data,
}

test example_swap() {
let addr =
Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
)
let dest = Destination { address: addr, datum: NoDatum }
let swap =
Swap(
(#"", #"", 10000000),
(
#"d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf",
#"44554d4d59",
0,
),
)
trace bytearray.to_hex(
cbor.serialise(
OrderDatum {
pool_ident: None,
owner: multisig.Signature(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
max_protocol_fee: 2500000,
destination: dest,
details: swap,
extension: Void,
},
),
)
True
}

test example_deposit() {
let addr =
Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
)
let dest = Destination { address: addr, datum: NoDatum }
let deposit =
Deposit((
(#"", #"", 10000000),
(
#"d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf",
#"44554d4d59",
10000000,
),
))
trace bytearray.to_hex(
cbor.serialise(
OrderDatum {
pool_ident: None,
owner: multisig.Signature(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
max_protocol_fee: 2500000,
destination: dest,
details: deposit,
extension: Void,
},
),
)
True
}

test example_withdrawal() {
let addr =
Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
)
let dest = Destination { address: addr, datum: NoDatum }
let withdrawal =
Withdrawal(
(
#"d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf",
#"6c",
10000000
),
)
trace bytearray.to_hex(
cbor.serialise(
OrderDatum {
pool_ident: None,
owner: multisig.Signature(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
max_protocol_fee: 2500000,
destination: dest,
details: withdrawal,
extension: Void,
},
),
)
True
}


// A destination consists of
pub type Destination {
// An address
Expand Down Expand Up @@ -175,9 +68,4 @@ pub type SignedStrategyExecution {
strategy: StrategyExecution,
// The signature of the bytes of Strategy
signature: Signature,
}

test example_swap_redeemer() {
trace bytearray.to_hex(cbor.serialise(Scoop))
True
}
}

0 comments on commit 102614a

Please sign in to comment.