From ed03123f7bff71e2e9b22852e531e312ca02e35d Mon Sep 17 00:00:00 2001 From: Francisco <121896075+franciscojoray@users.noreply.github.com> Date: Mon, 6 May 2024 16:52:54 -0300 Subject: [PATCH] reading pellet params from csv. (#58) * reading pellet params from csv. * removed asteria tx ref assuming unique UTxO. * added pellets tx indexing. * removed unused parsing option. * fixed type annotation. --- offchain/tests/admin/create-pellets.ts | 30 ++++++++++------------ offchain/tests/admin/pellets.csv | 6 +++++ offchain/tests/user/create-ship.ts | 10 ++------ offchain/tests/user/gather-fuel.ts | 8 +++--- offchain/tests/user/mine-asteria.ts | 14 ++-------- offchain/transactions/user/create-ship.ts | 13 ++-------- offchain/transactions/user/gather-fuel.ts | 5 ++-- offchain/transactions/user/mine-asteria.ts | 13 ++-------- 8 files changed, 35 insertions(+), 64 deletions(-) create mode 100644 offchain/tests/admin/pellets.csv diff --git a/offchain/tests/admin/create-pellets.ts b/offchain/tests/admin/create-pellets.ts index 2fd0518..3299eb1 100644 --- a/offchain/tests/admin/create-pellets.ts +++ b/offchain/tests/admin/create-pellets.ts @@ -1,24 +1,20 @@ import { admin_token } from "../../constants.ts"; import { createPellets } from "../../transactions/admin/create-pellets.ts"; import { printTxURL } from "../../utils.ts"; +import { parse } from "jsr:@std/csv"; -const params = [ - { - fuel: 90n, - pos_x: 12n, - pos_y: -50n, - }, - { - fuel: 40n, - pos_x: -7n, - pos_y: 3n, - }, - { - fuel: 25n, - pos_x: 20n, - pos_y: 19n, - }, -]; +const text = await Deno.readTextFile("tests/admin/pellets.csv"); +const data = parse(text, { + skipFirstRow: true, + columns: ["fuel", "pos_x", "pos_y"], +}); +const params: { fuel: bigint; pos_x: bigint; pos_y: bigint }[] = data.map( + (p) => ({ + fuel: BigInt(p.fuel), + pos_x: BigInt(p.pos_x), + pos_y: BigInt(p.pos_y), + }) +); const txHash = await createPellets(admin_token, params); printTxURL(txHash); diff --git a/offchain/tests/admin/pellets.csv b/offchain/tests/admin/pellets.csv new file mode 100644 index 0000000..a6ec836 --- /dev/null +++ b/offchain/tests/admin/pellets.csv @@ -0,0 +1,6 @@ +fuel,x,y +90,12,-35 +40,-8,3 +25,20,16 +36,-4,-17 +68,19,-10 \ No newline at end of file diff --git a/offchain/tests/user/create-ship.ts b/offchain/tests/user/create-ship.ts index 27db115..8d30af8 100644 --- a/offchain/tests/user/create-ship.ts +++ b/offchain/tests/user/create-ship.ts @@ -6,20 +6,14 @@ import { import { createShip } from "../../transactions/user/create-ship.ts"; import { printTxURL } from "../../utils.ts"; -const pos_x = -7n; +const pos_x = -8n; const pos_y = 3n; -const asteria_tx_hash = - "8884b2ccbb0d2cd5192459609f775f5b4e5681f5de8d6a4b6f9fc109ea601605"; -const asteria_tx_index = 0; const txHash = await createShip( admin_token, ship_mint_lovelace_fee, initial_fuel, pos_x, - pos_y, - asteria_tx_hash, - asteria_tx_index + pos_y ); - printTxURL(txHash); diff --git a/offchain/tests/user/gather-fuel.ts b/offchain/tests/user/gather-fuel.ts index 1fb5ae8..afc6730 100644 --- a/offchain/tests/user/gather-fuel.ts +++ b/offchain/tests/user/gather-fuel.ts @@ -4,15 +4,17 @@ import { printTxURL } from "../../utils.ts"; const gather_amount = 20n; const ship_tx_hash = - "6ca378639a51b1283ec2c84deb772f62bff59603eca230aeb711fedee8389d69"; + "f1079755f32839c7c55796335e6835a0aafa8ce9b3e15fed287e0d971826881c"; const pellet_tx_hash = - "b1d5dedc6c9ba333d8eab4c9f05edda4563fc313fc9b124393ec3b64e3676fb0"; + "f7f8f8298876cabb81357c1d7e89e2e01bf8956a566063f12ceee7b6901d0334"; +const pellet_tx_index = 1; const txHash = await gatherFuel( admin_token, gather_amount, ship_tx_hash, - pellet_tx_hash + pellet_tx_hash, + pellet_tx_index ); printTxURL(txHash); diff --git a/offchain/tests/user/mine-asteria.ts b/offchain/tests/user/mine-asteria.ts index ba7d314..b87810f 100644 --- a/offchain/tests/user/mine-asteria.ts +++ b/offchain/tests/user/mine-asteria.ts @@ -3,17 +3,7 @@ import { mineAsteria } from "../../transactions/user/mine-asteria.ts"; import { printTxURL } from "../../utils.ts"; const ship_tx_hash = - "a528f7e89227b16d769e46b81fae20ba223b3f8fd23d82bb61aa6298f53eb5be"; -const asteria_tx_hash = - "aff7cd18d9bf623cdf94544837a450323db2298913b7f6d353e51d9ac109a72a"; -const asteria_tx_index = 1; - -const txHash = await mineAsteria( - admin_token, - max_asteria_mining, - ship_tx_hash, - asteria_tx_hash, - asteria_tx_index -); + "63213819a91009d48fda251fa5d735ba7fc17ff2d64558c167aa037919adcd05"; +const txHash = await mineAsteria(admin_token, max_asteria_mining, ship_tx_hash); printTxURL(txHash); diff --git a/offchain/transactions/user/create-ship.ts b/offchain/transactions/user/create-ship.ts index 04586df..4e9b765 100644 --- a/offchain/transactions/user/create-ship.ts +++ b/offchain/transactions/user/create-ship.ts @@ -21,9 +21,7 @@ async function createShip( ship_mint_lovelace_fee: bigint, initial_fuel: bigint, pos_x: bigint, - pos_y: bigint, - asteria_tx_hash: TxHash, - asteria_tx_index: number + pos_y: bigint ): Promise { const lucid = await lucidBase(); const seed = Deno.env.get("SEED"); @@ -51,14 +49,7 @@ async function createShip( const spacetimeAddressBech32 = lucid.utils.validatorToAddress(spacetimeValidator); - const asteria: UTxO = ( - await lucid.utxosByOutRef([ - { - txHash: asteria_tx_hash, - outputIndex: asteria_tx_index, - }, - ]) - )[0]; + const asteria: UTxO = (await lucid.utxosAt(asteriaAddressBech32))[0]; if (!asteria.datum) { throw Error("Asteria datum not found"); } diff --git a/offchain/transactions/user/gather-fuel.ts b/offchain/transactions/user/gather-fuel.ts index 707317d..56ac4c3 100644 --- a/offchain/transactions/user/gather-fuel.ts +++ b/offchain/transactions/user/gather-fuel.ts @@ -19,7 +19,8 @@ async function gatherFuel( admin_token: AssetClassT, gather_amount: bigint, ship_tx_hash: TxHash, - pellet_tx_hash: TxHash + pellet_tx_hash: TxHash, + pellet_tx_index: number ): Promise { const lucid = await lucidBase(); const seed = Deno.env.get("SEED"); @@ -64,7 +65,7 @@ async function gatherFuel( await lucid.utxosByOutRef([ { txHash: pellet_tx_hash, - outputIndex: 0, + outputIndex: pellet_tx_index, }, ]) )[0]; diff --git a/offchain/transactions/user/mine-asteria.ts b/offchain/transactions/user/mine-asteria.ts index 2c44264..bb38092 100644 --- a/offchain/transactions/user/mine-asteria.ts +++ b/offchain/transactions/user/mine-asteria.ts @@ -18,9 +18,7 @@ import { async function mineAsteria( admin_token: AssetClassT, max_asteria_mining: bigint, - ship_tx_hash: TxHash, - asteria_tx_hash: TxHash, - asteria_tx_index: number + ship_tx_hash: TxHash ): Promise { const lucid = await lucidBase(); const seed = Deno.env.get("SEED"); @@ -63,14 +61,7 @@ async function mineAsteria( ShipDatum as unknown as ShipDatumT ); - const asteria: UTxO = ( - await lucid.utxosByOutRef([ - { - txHash: asteria_tx_hash, - outputIndex: asteria_tx_index, - }, - ]) - )[0]; + const asteria: UTxO = (await lucid.utxosAt(asteriaAddressBech32))[0]; if (!asteria.datum) { throw Error("Asteria datum not found"); }