Skip to content

Commit

Permalink
feat: building content ref token test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Nov 26, 2023
1 parent e0e7f5c commit 48db192
Showing 1 changed file with 110 additions and 19 deletions.
129 changes: 110 additions & 19 deletions validators/content_registry_ref_token.ak
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use aiken/dict
// use aiken/list
use aiken/transaction.{
InlineDatum, Input, Mint, ScriptContext, Transaction, placeholder,
InlineDatum, Input, Mint, Output, ScriptContext, Transaction, placeholder,
}
use aiken/transaction/value.{PolicyId, from_asset, to_minted_value}
use aiken/transaction/value.{PolicyId, add, from_asset, to_minted_value}
use aiken_content_ownership/common.{inputs_with, outputs_at_with, value_length}
use aiken_content_ownership/placeholder.{
mock_content_registry_datum, mock_content_registry_output, mock_oracle_datum,
mock_oracle_output, mock_policy_id, mock_policy_id_2, mock_utxo_ref,
mock_oracle_output, mock_policy_id, mock_policy_id_2, mock_policy_id_3,
mock_utxo_ref,
}
use aiken_content_ownership/types.{
ContentRegistryDatum, MintPolarity, OracleDatum, RBurn, RMint,
Expand Down Expand Up @@ -75,43 +76,133 @@ validator(oracle_nft: PolicyId) {
}
}

fn make_mock_tx_body(record_count: Int) -> Transaction {
type TestCase {
is_oracle_updated: Bool,
is_registry_initialized: Bool,
is_oracle_value_clean: Bool,
is_registry_value_clean: Bool,
}

fn default_test_case() -> TestCase {
TestCase {
is_oracle_updated: True,
is_registry_initialized: True,
is_oracle_value_clean: True,
is_registry_value_clean: True,
}
}

fn make_mock_tx_body(record_count: Int, test_case: TestCase) -> Transaction {
let registry_token_value =
from_asset(mock_policy_id_2(), get_registry_token_name(record_count), 1)
let TestCase {
is_oracle_updated,
is_registry_initialized,
is_oracle_value_clean,
is_registry_value_clean,
} = test_case
let new_count =
if is_oracle_updated {
record_count + 1
} else {
record_count
}
let new_registry =
if is_registry_initialized {
mock_content_registry_datum(0, dict.new())
} else {
mock_content_registry_datum(1, dict.new())
}
let oracle_value =
if is_oracle_value_clean {
from_asset(mock_policy_id(), "", 1) |> add(#"", #"", 2_000_000)
} else {
from_asset(mock_policy_id(), "", 1)
|> add(#"", #"", 2_000_000)
|> add(mock_policy_id_3(), "123", 1)
}
let registry_value =
if is_registry_value_clean {
registry_token_value |> add(#"", #"", 2_000_000)
} else {
registry_token_value
|> add(#"", #"", 2_000_000)
|> add(mock_policy_id_3(), "123", 1)
}
Transaction {
..placeholder(),
mint: to_minted_value(
from_asset(mock_policy_id_2(), get_registry_token_name(record_count), 1),
),
mint: to_minted_value(registry_token_value),
inputs: [
Input {
output_reference: mock_utxo_ref(1),
output: mock_oracle_output(mock_oracle_datum()),
},
],
outputs: [
mock_oracle_output(
OracleDatum {
..mock_oracle_datum(),
content_registry_count: record_count + 1,
},
),
mock_content_registry_output(
record_count,
mock_content_registry_datum(0, dict.new()),
),
Output {
..mock_oracle_output(
OracleDatum {
..mock_oracle_datum(),
content_registry_count: new_count,
},
),
value: oracle_value,
},
Output {
..mock_content_registry_output(record_count, new_registry),
value: registry_value,
},
],
}
}

test success_mint() {
let redeemer = RMint
let tx = make_mock_tx_body(0)
let tx = make_mock_tx_body(0, default_test_case())
let ctx = ScriptContext { purpose: Mint(mock_policy_id_2()), transaction: tx }
content_registry_ref_token(mock_policy_id(), redeemer, ctx)
}

test fail_mint_without_update_oracle() {
let redeemer = RMint
let tx = make_mock_tx_body(0)
let tx =
make_mock_tx_body(
0,
TestCase { ..default_test_case(), is_oracle_updated: False },
)
let ctx = ScriptContext { purpose: Mint(mock_policy_id()), transaction: tx }
!content_registry_ref_token(mock_policy_id(), redeemer, ctx)
}

test fail_mint_without_registry_initialized() {
let redeemer = RMint
let tx =
make_mock_tx_body(
0,
TestCase { ..default_test_case(), is_registry_initialized: False },
)
let ctx = ScriptContext { purpose: Mint(mock_policy_id()), transaction: tx }
!content_registry_ref_token(mock_policy_id(), redeemer, ctx)
}

test fail_mint_with_unclean_oracle_value() {
let redeemer = RMint
let tx =
make_mock_tx_body(
0,
TestCase { ..default_test_case(), is_oracle_value_clean: False },
)
let ctx = ScriptContext { purpose: Mint(mock_policy_id()), transaction: tx }
!content_registry_ref_token(mock_policy_id(), redeemer, ctx)
}

test fail_mint_with_unclean_registry_value() {
let redeemer = RMint
let tx =
make_mock_tx_body(
0,
TestCase { ..default_test_case(), is_registry_value_clean: False },
)
let ctx = ScriptContext { purpose: Mint(mock_policy_id()), transaction: tx }
!content_registry_ref_token(mock_policy_id(), redeemer, ctx)
}

0 comments on commit 48db192

Please sign in to comment.