Skip to content

Commit

Permalink
feat: building create content registry unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Nov 27, 2023
1 parent fcb130f commit 786adf6
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 345 deletions.
4 changes: 4 additions & 0 deletions lib/aiken-content-ownership/placeholder.ak
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ pub fn mock_policy_id_3() -> PolicyId {
#"a15cd6051ea2fc92c034b0bb1d33f2b7ba7ac92277e6ee5c30ab19a4"
}

pub fn mock_policy_id_4() -> PolicyId {
#"c0f778be07f8b129d2546ad37b0e13b3486747dfe1767ff8e7e8a4f3"
}

pub fn mock_utxo_ref(output_index: Int) -> OutputReference {
OutputReference {
transaction_id: TransactionId(
Expand Down
9 changes: 6 additions & 3 deletions lib/aiken-content-ownership/validators/content_registry.ak
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn content_registry_logic(
let ref_tokens_equal =
content_ref_token_name == ownership_ref_token_name
let current_count_equal =
content_input_datum.count == content_output_datum.count
content_input_datum.count == ownership_input_datum.count
let content_new_datum_correct =
content_output_datum == ContentRegistryDatum {
count: content_input_datum.count + 1,
Expand All @@ -111,12 +111,15 @@ pub fn content_registry_logic(
int.compare,
),
}
ref_tokens_equal && current_count_equal && content_new_datum_correct && ownership_new_datum_correct
let content_registry_value_clean =
list.length(flatten(content_output.value)) == 2
let ownership_registry_value_clean =
list.length(flatten(ownership_output.value)) == 2
ref_tokens_equal && current_count_equal && content_new_datum_correct && ownership_new_datum_correct && content_registry_value_clean && ownership_registry_value_clean
}
_ -> False
}
}

_ -> False
}
}
87 changes: 2 additions & 85 deletions validators/oracle_validator.ak
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
use aiken/transaction.{Input, ScriptContext, Spend, Transaction, placeholder}
use aiken/transaction/value.{PolicyId, from_asset, to_minted_value}
use aiken_content_ownership/placeholder.{
mock_oracle_datum, mock_oracle_output, mock_policy_id, mock_policy_id_2,
mock_policy_id_3, mock_utxo_ref, mock_vkey_hex, mock_vkey_hex_2,
}
use aiken_content_ownership/types.{
CreateContentRegistry, CreateOwnershipRegistry, OracleDatum, OracleRedeemer,
RotateKey, StopApp,
}
use aiken/transaction.{ScriptContext}
use aiken_content_ownership/types.{OracleDatum, OracleRedeemer}
use aiken_content_ownership/validators/oracle_validator.{oracle_validator_logic}

validator {
Expand All @@ -19,78 +11,3 @@ validator {
oracle_validator_logic(datum, redeemer, context)
}
}

test success_create_content_registry() {
let redeemer = CreateContentRegistry
let policy_id: PolicyId = mock_policy_id_2()

let tx =
Transaction {
..placeholder(),
mint: to_minted_value(from_asset(policy_id, "Registry (0)", 1)),
}
let ctx = ScriptContext { purpose: Spend(mock_utxo_ref(0)), transaction: tx }

oracle_validator(mock_oracle_datum(), redeemer, ctx)
}

test success_create_ownership_registry() {
let redeemer = CreateOwnershipRegistry
let policy_id: PolicyId = mock_policy_id_3()

let tx =
Transaction {
..placeholder(),
mint: to_minted_value(from_asset(policy_id, "Registry (0)", 1)),
}
let ctx = ScriptContext { purpose: Spend(mock_utxo_ref(0)), transaction: tx }

oracle_validator(mock_oracle_datum(), redeemer, ctx)
}

test success_rotate_key() {
let redeemer =
RotateKey {
new_operation_key: mock_vkey_hex_2(),
new_stop_key: mock_vkey_hex(),
}

let input_utxo = mock_utxo_ref(0)
let input =
Input {
output_reference: input_utxo,
output: mock_oracle_output(mock_oracle_datum()),
}
let output =
mock_oracle_output(
OracleDatum {
..mock_oracle_datum(),
operation_key: mock_vkey_hex_2(),
stop_key: mock_vkey_hex(),
},
)

let tx =
Transaction {
..placeholder(),
inputs: [input],
outputs: [output],
extra_signatories: [mock_vkey_hex(), mock_vkey_hex_2()],
}
let ctx = ScriptContext { purpose: Spend(input_utxo), transaction: tx }

oracle_validator(mock_oracle_datum(), redeemer, ctx)
}

test success_stop_app() {
let redeemer = StopApp
let tx =
Transaction {
..placeholder(),
mint: to_minted_value(from_asset(mock_policy_id(), "", -1)),
extra_signatories: [mock_vkey_hex_2()],
}
let ctx = ScriptContext { purpose: Spend(mock_utxo_ref(0)), transaction: tx }

oracle_validator(mock_oracle_datum(), redeemer, ctx)
}
Loading

0 comments on commit 786adf6

Please sign in to comment.