Skip to content

Commit

Permalink
migrate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Nov 17, 2024
1 parent e161751 commit 692e503
Show file tree
Hide file tree
Showing 18 changed files with 693 additions and 737 deletions.
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmpdata
28 changes: 28 additions & 0 deletions inspiration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Inspiration

## Analogs
Capture-the-flag in Cardano
https://medium.com/@vacuumlabs_auditing/announcing-the-first-cardano-ctf-a2476e154a55
https://github.com/vacuumlabs/cardano-ctf

## Backstory

Example of how to present backstory in a concise way
https://fractalsoftworks.com/

Reddit thread with space MMORPG recommendations
https://www.reddit.com/r/MMORPG/comments/gplriw/looking_for_a_recommendation_space_mmo_with/

## Graphics

Pixel-Font generator
https://fontmeme.com/pixel-fonts/#google_vignette

Space pixel-art tutorial
https://www.youtube.com/watch?app=desktop&v=BdFm07xpEhM

Game kit
https://www.dreamstime.com/bit-pixel-art-game-asset-space-planets-rockets-bit-pixel-art-game-asset-space-planets-rockets-starcraft-vector-font-image236327740

Game Kit
https://www.dreamstime.com/pixel-game-space-planets-stars-asteroids-set-comets-vector-bit-solar-system-fantasy-objects-retro-graphic-sci-fi-astronomical-image241723790
4 changes: 2 additions & 2 deletions onchain/src/aiken.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

[[requirements]]
name = "aiken-lang/stdlib"
version = "1.7.0"
version = "v2.1.0"
source = "github"

[[packages]]
name = "aiken-lang/stdlib"
version = "1.7.0"
version = "v2.1.0"
requirements = []
source = "github"

Expand Down
6 changes: 3 additions & 3 deletions onchain/src/lib/asteria/test_utils.ak
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use aiken/bytearray
use aiken/transaction.{Mint, ScriptPurpose, Spend}
use aiken/primitive/bytearray
use cardano/transaction.{Mint, ScriptPurpose, Spend}

/// Converts a given ScriptPurpose into a ByteArray representation.
///
Expand All @@ -14,7 +14,7 @@ use aiken/transaction.{Mint, ScriptPurpose, Spend}
/// A `ByteArray` representation of the provided `ScriptPurpose`.
fn script_purpose_to_byte_array(sp: ScriptPurpose) -> ByteArray {
when sp is {
Spend(ref) -> ref.transaction_id.hash
Spend(ref) -> ref.transaction_id
Mint(policy_id) -> policy_id

// Default case to handle any other unexpected variants.
Expand Down
213 changes: 151 additions & 62 deletions onchain/src/plutus.json

Large diffs are not rendered by default.

86 changes: 37 additions & 49 deletions onchain/src/validators/tests/asteria/add_new_ship.ak
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use aiken/bytearray
use aiken/dict
use aiken/collection/dict
use aiken/interval.{Finite, Interval, IntervalBound}
use aiken/transaction.{
InlineDatum, Input, Output, OutputReference, ScriptContext, Spend, Transaction,
TransactionId,
}
use aiken/transaction/credential.{Address, ScriptCredential}
use aiken/transaction/value.{ada_asset_name, ada_policy_id}
use asteria
use asteria/test_mock as mock
use asteria/test_utils
use asteria/types.{AddNewShip, AssetClass, AsteriaDatum}
use cardano/address.{Address, Script}
use cardano/assets.{ada_asset_name, ada_policy_id, add, from_lovelace, zero}
use cardano/transaction.{
InlineDatum, Input, Output, OutputReference, Spend, Transaction,
}

// ==============================================================================================
// AddNewShip Tests
Expand Down Expand Up @@ -41,15 +38,15 @@ fn addNewShip(options: AddTestOptions) -> Bool {
let redeemer = AddNewShip
let asteria_address =
Address {
payment_credential: ScriptCredential(mock.asteria_credential),
payment_credential: Script(mock.asteria_credential),
stake_credential: None,
}
let asteria_value =
if options.include_admin_token {
value.from_lovelace(10_000_000)
|> value.add(mock.admin_policy, mock.admin_token_name, 1)
from_lovelace(10_000_000)
|> add(mock.admin_policy, mock.admin_token_name, 1)
} else {
value.from_lovelace(10_000_000)
from_lovelace(10_000_000)
}
let asteria_datum =
AsteriaDatum { ship_counter, shipyard_policy: mock.shipyard_policy }
Expand All @@ -62,18 +59,15 @@ fn addNewShip(options: AddTestOptions) -> Bool {
reference_script: None,
}
let output_reference =
OutputReference {
transaction_id: TransactionId { hash: mock.transaction_id_1 },
output_index: 0,
}
OutputReference { transaction_id: mock.transaction_id_1, output_index: 0 }
Input { output_reference, output }
}
let asteria_out =
Output {
address: asteria_address,
value: if options.pay_fee {
asteria_in.output.value
|> value.add(ada_policy_id, ada_asset_name, ship_mint_lovelace_fee)
|> add(ada_policy_id, ada_asset_name, ship_mint_lovelace_fee)
} else {
asteria_in.output.value
},
Expand All @@ -93,10 +87,10 @@ fn addNewShip(options: AddTestOptions) -> Bool {
inputs: [asteria_in],
reference_inputs: [],
outputs: [asteria_out],
fee: value.from_lovelace(5_000),
mint: value.to_minted_value(value.zero()),
fee: 5_000,
mint: zero,
certificates: [],
withdrawals: dict.new(),
withdrawals: [],
validity_range: Interval {
lower_bound: IntervalBound { bound_type: Finite(1), is_inclusive: True },
upper_bound: IntervalBound {
Expand All @@ -105,49 +99,43 @@ fn addNewShip(options: AddTestOptions) -> Bool {
},
},
extra_signatories: [],
redeemers: dict.new()
|> dict.insert(
key: Spend(
OutputReference {
transaction_id: TransactionId { hash: mock.transaction_id_1 },
output_index: 0,
},
),
value: {
let redeemer_data: Data = redeemer
redeemer_data
redeemers: [
Pair(
Spend(
OutputReference {
transaction_id: mock.transaction_id_1,
output_index: 0,
},
compare: test_utils.script_purpose_compare,
),
datums: dict.new()
{
let redeemer_data: Data = redeemer
redeemer_data
},
),
],
datums: dict.empty
|> dict.insert(
mock.transaction_id_1,
{
let datum_data: Data = InlineDatum(asteria_datum)
datum_data
},
compare: bytearray.compare,
),
id: TransactionId { hash: mock.transaction_id_3 },
}
let spend_ctx =
ScriptContext {
transaction: tx,
purpose: Spend(
OutputReference {
transaction_id: TransactionId { hash: mock.transaction_id_1 },
output_index: 0,
},
),
id: mock.transaction_id_3,
votes: [],
proposal_procedures: [],
current_treasury_amount: None,
treasury_donation: None,
}
let result =
asteria.spend(
asteria.asteria.spend(
admin_token,
ship_mint_lovelace_fee,
max_asteria_mining,
asteria_datum,
Some(asteria_datum),
redeemer,
spend_ctx,
OutputReference { transaction_id: mock.transaction_id_1, output_index: 0 },
tx,
)
result
}
Expand Down
97 changes: 40 additions & 57 deletions onchain/src/validators/tests/asteria/consume.ak
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
use aiken/bytearray
use aiken/dict
use aiken/collection/dict
use aiken/interval.{Finite, Interval, IntervalBound}
use aiken/transaction.{
InlineDatum, Input, NoDatum, Output, OutputReference, ScriptContext, Spend,
Transaction, TransactionId,
}
use aiken/transaction/credential.{
Address, ScriptCredential, VerificationKeyCredential,
}
use aiken/transaction/value
use asteria
use asteria/test_mock as mock
use asteria/test_utils
use asteria/types.{AssetClass, AsteriaDatum, ConsumeAsteria}
use cardano/address.{Address, Script, VerificationKey}
use cardano/assets.{add, from_lovelace, zero}
use cardano/transaction.{
InlineDatum, Input, NoDatum, Output, OutputReference, Spend, Transaction,
}

// ==============================================================================================
// Consume Tests
Expand All @@ -38,17 +33,17 @@ fn consume(options: ConsumeTestOptions) -> Bool {
let admin_address =
Address {
payment_credential: if options.is_wallet_address {
VerificationKeyCredential(mock.admin_credential)
VerificationKey(mock.admin_credential)
} else {
ScriptCredential(mock.admin_credential)
Script(mock.admin_credential)
},
stake_credential: None,
}
let admin_in = {
let output = {
let value =
value.from_lovelace(2_000_000)
|> value.add(admin_token.policy, admin_token.name, 1)
from_lovelace(2_000_000)
|> add(admin_token.policy, admin_token.name, 1)
Output {
address: admin_address,
value,
Expand All @@ -57,16 +52,13 @@ fn consume(options: ConsumeTestOptions) -> Bool {
}
}
let output_reference =
OutputReference {
transaction_id: TransactionId { hash: mock.transaction_id_2 },
output_index: 0,
}
OutputReference { transaction_id: mock.transaction_id_2, output_index: 0 }
Input { output_reference, output }
}

let asteria_address =
Address {
payment_credential: ScriptCredential(mock.asteria_credential),
payment_credential: Script(mock.asteria_credential),
stake_credential: None,
}
let asteria_datum =
Expand All @@ -75,16 +67,13 @@ fn consume(options: ConsumeTestOptions) -> Bool {
let output =
Output {
address: asteria_address,
value: value.from_lovelace(12_000_000)
|> value.add(mock.admin_policy, mock.admin_token_name, 1),
value: from_lovelace(12_000_000)
|> add(mock.admin_policy, mock.admin_token_name, 1),
datum: InlineDatum(asteria_datum),
reference_script: None,
}
let output_reference =
OutputReference {
transaction_id: TransactionId { hash: mock.transaction_id_1 },
output_index: 0,
}
OutputReference { transaction_id: mock.transaction_id_1, output_index: 0 }
Input { output_reference, output }
}

Expand All @@ -97,10 +86,10 @@ fn consume(options: ConsumeTestOptions) -> Bool {
},
reference_inputs: [],
outputs: [],
fee: value.from_lovelace(5_000),
mint: value.to_minted_value(value.zero()),
fee: 5_000,
mint: zero,
certificates: [],
withdrawals: dict.new(),
withdrawals: [],
validity_range: Interval {
lower_bound: IntervalBound { bound_type: Finite(1), is_inclusive: True },
upper_bound: IntervalBound {
Expand All @@ -109,49 +98,43 @@ fn consume(options: ConsumeTestOptions) -> Bool {
},
},
extra_signatories: [],
redeemers: dict.new()
|> dict.insert(
key: Spend(
OutputReference {
transaction_id: TransactionId { hash: mock.transaction_id_1 },
output_index: 0,
},
),
value: {
let redeemer_data: Data = redeemer
redeemer_data
redeemers: [
Pair(
Spend(
OutputReference {
transaction_id: mock.transaction_id_1,
output_index: 0,
},
compare: test_utils.script_purpose_compare,
),
datums: dict.new()
{
let redeemer_data: Data = redeemer
redeemer_data
},
),
],
datums: dict.empty
|> dict.insert(
mock.transaction_id_1,
{
let datum_data: Data = InlineDatum(asteria_datum)
datum_data
},
compare: bytearray.compare,
),
id: TransactionId { hash: mock.transaction_id_3 },
}
let spend_ctx =
ScriptContext {
transaction: tx,
purpose: Spend(
OutputReference {
transaction_id: TransactionId { hash: mock.transaction_id_1 },
output_index: 0,
},
),
id: mock.transaction_id_3,
votes: [],
proposal_procedures: [],
current_treasury_amount: None,
treasury_donation: None,
}
let result =
asteria.spend(
asteria.asteria.spend(
admin_token,
ship_mint_lovelace_fee,
max_asteria_mining,
asteria_datum,
Some(asteria_datum),
redeemer,
spend_ctx,
OutputReference { transaction_id: mock.transaction_id_1, output_index: 0 },
tx,
)
result
}
Expand Down
Loading

0 comments on commit 692e503

Please sign in to comment.