Skip to content

Commit

Permalink
Start to pull examples and tests into their own folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Dec 9, 2023
1 parent 72af6e7 commit 8c9b264
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 113 deletions.
Empty file added lib/tests/aiken/settings.ak
Empty file.
75 changes: 75 additions & 0 deletions lib/tests/examples/ex_settings.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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}

pub fn mk_valid_settings_datum(
scoopers: List<ByteArray>,
) -> SettingsDatum {
SettingsDatum {
settings_admin: multisig.Signature(
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad",
),
metadata_admin: Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
),
treasury_admin: multisig.Signature(
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad",
),
treasury_address: Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
),
treasury_allowance: (1, 10),
authorized_scoopers: scoopers,
authorized_staking_keys: [
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad",
],
base_fee: 0,
simple_fee: 2_500_000,
strategy_fee: 5_000_000,
extensions: Void,
}
}

pub fn mk_valid_settings_input(
scoopers: List<ByteArray>,
ix: Int,
) -> Input {
let hash_of_settings_script =
#"00000000000000000000000000000000000000000000000000000000"
let settings_nft_name = "settings"
let settings_address = script_address(hash_of_settings_script)
let settings_datum = mk_valid_settings_datum(scoopers)

let settings_input =
Input {
output_reference: mk_output_reference(ix),
output: Output {
address: settings_address,
value: value.from_lovelace(2_000_000)
|> value.add(hash_of_settings_script, settings_nft_name, 1),
datum: InlineDatum(settings_datum),
reference_script: None,
},
}
settings_input
}

test example_settings_datum() {
trace bytearray.to_hex(
cbor.serialise(mk_valid_settings_datum([
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad",
])),
)
True
}
25 changes: 25 additions & 0 deletions lib/tests/examples/ex_shared.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use aiken/bytearray
use aiken/transaction.{OutputReference, TransactionId}
use aiken/transaction/credential.{Address, ScriptCredential, VerificationKeyCredential}

pub fn mk_tx_hash(n: Int) -> TransactionId {
expect n < 256
let h =
bytearray.push(
#"00000000000000000000000000000000000000000000000000000000000000",
n,
)
TransactionId { hash: h }
}

pub fn mk_output_reference(n: Int) -> OutputReference {
OutputReference { transaction_id: mk_tx_hash(0), output_index: n }
}

pub fn script_address(hash: ByteArray) -> Address {
Address { payment_credential: ScriptCredential(hash), stake_credential: None }
}

pub fn wallet_address(hash: ByteArray) -> Address {
Address(VerificationKeyCredential(hash), None)
}
44 changes: 1 addition & 43 deletions lib/types/settings.ak
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use aiken/bytearray
use aiken/cbor
use aiken/transaction/credential.{Address, VerificationKey, VerificationKeyCredential}
use aiken/transaction/credential.{Address, VerificationKey}
use sundae/multisig.{MultisigScript}
use shared.{Rational}
use aiken/transaction.{
Expand Down Expand Up @@ -49,43 +47,3 @@ pub fn find_settings_datum(reference_inputs: List<Input>, settings_policy_id: Po
expect settings_datum: SettingsDatum = settings_datum
settings_datum
}

test example_settings_datum() {
trace bytearray.to_hex(
cbor.serialise(
SettingsDatum {
pool_script_hash: #"596a9815c479a00f894a5a61f64d1f508635dd4e809b29ce1c4afadc",
settings_admin: multisig.Signature(
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad",
),
metadata_admin: Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
),
treasury_admin: multisig.Signature(
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad",
),
treasury_address: Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
),
treasury_allowance: (1, 10),
authorized_scoopers: [
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad",
],
authorized_staking_keys: [
#"725011d2c296eb3341e159b6c5c6991de11e81062b95108c9aa024ad",
],
base_fee: 1_000_000,
simple_fee: 100_000,
strategy_fee: 200_000,
extensions: Void,
},
),
)
True
}
75 changes: 5 additions & 70 deletions validators/pool.ak
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use calculation/process.{pool_input_to_state, process_orders}
use calculation/shared.{PoolState} as calc_shared
use shared.{AssetClass, Ident, spent_output, pool_nft_name, pool_lp_name, has_exact_token_count, count_orders}
use sundae/multisig
use tests/examples/ex_settings.{mk_valid_settings_input}
use tests/examples/ex_shared.{wallet_address, script_address, mk_output_reference, mk_tx_hash}
use types/order.{Destination, OrderDatum, Swap, Deposit}
use types/pool.{
CreatePool, MintLP, PoolDatum, PoolMintRedeemer, PoolRedeemer, PoolScoop, WithdrawFees
Expand Down Expand Up @@ -383,73 +385,6 @@ validator(settings_policy_id: PolicyId) {
}
}

fn mk_tx_hash(n: Int) -> TransactionId {
expect n < 256
let h =
bytearray.push(
#"00000000000000000000000000000000000000000000000000000000000000",
n,
)
TransactionId { hash: h }
}

fn mk_output_reference(n: Int) -> OutputReference {
OutputReference { transaction_id: mk_tx_hash(0), output_index: n }
}

fn script_address(hash: ByteArray) -> Address {
Address { payment_credential: ScriptCredential(hash), stake_credential: None }
}

fn wallet_address(hash: ByteArray) -> Address {
Address(VerificationKeyCredential(hash), None)
}

fn mk_settings_input(
scoopers: List<ByteArray>,
ix: Int,
) -> Input {
let hash_of_settings_script =
#"00000000000000000000000000000000000000000000000000000000"
let settings_nft_name = "settings"
let settings_address = script_address(hash_of_settings_script)
let settings_datum =
SettingsDatum {
settings_admin: multisig.AnyOf([]),
metadata_admin: Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
),
treasury_admin: multisig.AnyOf([]),
treasury_address: Address(
VerificationKeyCredential(
#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513",
),
None,
),
treasury_allowance: (1, 10),
authorized_scoopers: scoopers,
authorized_staking_keys: [],
base_fee: 0,
simple_fee: 2_500_000,
strategy_fee: 5_000_000,
extensions: Void,
}
let settings_input =
Input {
output_reference: mk_output_reference(ix),
output: Output {
address: settings_address,
value: value.from_lovelace(2_000_000)
|> value.add(hash_of_settings_script, settings_nft_name, 1),
datum: InlineDatum(settings_datum),
reference_script: None,
},
}
settings_input
}

type ScoopTestOptions {
edit_escrow_1_value: Option<Value>,
Expand Down Expand Up @@ -698,7 +633,7 @@ fn scoop(options: ScoopTestOptions) {
}
let settings_input = {
let Input { output_reference, output } =
mk_settings_input([scooper], 1)
mk_valid_settings_input([scooper], 1)
let updated_output =
Output {
..output,
Expand Down Expand Up @@ -866,7 +801,7 @@ fn scoop_swap_deposit(options: ScoopTestOptions) {
},
}
let settings_input = {
let Input {output_reference, output} = mk_settings_input([scooper], 1)
let Input {output_reference, output} = mk_valid_settings_input([scooper], 1)
let updated_output = Output {
..output,
datum: option.or_else(options.edit_settings_datum, output.datum)
Expand Down Expand Up @@ -935,7 +870,7 @@ test mint_test() {
let rberry_token_name = #"524245525259"
let user_address =
wallet_address(#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513")
let settings_input = mk_settings_input([], 1)
let settings_input = mk_valid_settings_input([], 1)
let funds_input = Input {
output_reference: OutputReference {
transaction_id: mk_tx_hash(0),
Expand Down

0 comments on commit 8c9b264

Please sign in to comment.