diff --git a/lib/tests/aiken/settings.ak b/lib/tests/aiken/settings.ak new file mode 100644 index 0000000..e69de29 diff --git a/lib/tests/examples/ex_settings.ak b/lib/tests/examples/ex_settings.ak new file mode 100644 index 0000000..9c29c0f --- /dev/null +++ b/lib/tests/examples/ex_settings.ak @@ -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, +) -> 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, + 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 +} \ No newline at end of file diff --git a/lib/tests/examples/ex_shared.ak b/lib/tests/examples/ex_shared.ak new file mode 100644 index 0000000..eb30190 --- /dev/null +++ b/lib/tests/examples/ex_shared.ak @@ -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) +} \ No newline at end of file diff --git a/lib/types/settings.ak b/lib/types/settings.ak index b10afe0..7eacbc4 100644 --- a/lib/types/settings.ak +++ b/lib/types/settings.ak @@ -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.{ @@ -49,43 +47,3 @@ pub fn find_settings_datum(reference_inputs: List, 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 -} diff --git a/validators/pool.ak b/validators/pool.ak index cb4afd3..d4d8980 100644 --- a/validators/pool.ak +++ b/validators/pool.ak @@ -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 @@ -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, - 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, @@ -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, @@ -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) @@ -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),