Skip to content

Commit 66feea6

Browse files
committed
feat: Add toolkit commands for bridge transfers.
To enable easy testing, update local-environment to use the same token as e2e tests, instead of obsolete token that came from partner-chains. Signed-off-by: Lech Głowiak <lech.glowiak@shielded.io>
1 parent 55e55c6 commit 66feea6

20 files changed

Lines changed: 454 additions & 38 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ sp-consensus = { default-features = false, git = "https://github.com/paritytech/
341341
sp-std = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2603" }
342342
substrate-test-runtime-client = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2603" }
343343

344+
whisky = { git = "https://github.com/midnightntwrk/whisky", branch = "wasm-bindgen-update" }
345+
344346
[profile.release]
345347
panic = "unwind"
346348

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#toolkit
2+
3+
# Add commands for initiating bridge transfers.
4+
5+
Adds `bridge-transfer` command that submits transaction to Cardano. Transaction is from user wallet to ICS address and has metadata that encodes either: transfer to specified Midnight UserAddress, to reserve or invalid one (will end up in Treasury).
6+
local-environment setup now mints the same token that e2e-tests use a "test cNight". Earlier it was creating obsolete token from partner-chains local-env tests.
7+
8+
#PR: https://github.com/midnightntwrk/midnight-node/pull/1340
9+
Required for https://github.com/midnightntwrk/midnight-node/issues/1086

local-environment/src/networks/local-env/configurations/cardano/entrypoint.sh

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,10 @@ fi
191191
set -x
192192

193193
echo "Preparing native token owned by 'funded_address.skey'"
194-
# Policy requires that mints are signed by the funded_address.skey (key hash is e8c300330fe315531ca89d4a2e7d0c80211bc70b473b1ed4979dff2b)
195-
reward_token_policy_id=$(cardano-cli latest transaction policyid --script-file ./shared/reward_token_policy.script)
196-
# hex of "Reward token"
197-
reward_token_asset_name="52657761726420746f6b656e"
198-
echo "Generating new address and funding it with 2x1000 Ada and 10 Ada + 1000000 reward token ($reward_token_policy_id.$reward_token_asset_name)"
194+
195+
test_cnight_policy_id=$(cardano-cli latest transaction policyid --script-file ./shared/test_cnight.script)
196+
197+
echo "Generating new address and funding it with 2x1000 Ada and 10 Ada + 1000000 test cNight ($test_cnight_policy_id.)"
199198

200199
new_address=$(cardano-cli latest address build \
201200
--payment-verification-key-file /keys/funded_address.vkey \
@@ -205,8 +204,6 @@ echo "New address created: $new_address"
205204

206205
dave_address="addr_test1vphpcf32drhhznv6rqmrmgpuwq06kug0lkg22ux777rtlqst2er0r"
207206
eve_address="addr_test1vzzt5pwz3pum9xdgxalxyy52m3aqur0n43pcl727l37ggscl8h7v8"
208-
# An address that will keep an UTXO with script of a test V-function, related to the SPO rewards. See v-function.script file.
209-
vfunction_address="addr_test1vzuasm5nqzh7n909f7wang7apjprpg29l2f9sk6shlt84rqep6nyc"
210207

211208
# Query the genesis UTXO dynamically (the UTXO ID changes when genesis time changes)
212209
genesis_address=$(cat /shared/shelley/genesis-utxo.addr)
@@ -216,14 +213,14 @@ echo "Genesis address: $genesis_address"
216213
for i in {1..30}; do
217214
echo "Querying genesis UTXO (attempt $i/30)..."
218215
cardano-cli latest query utxo --output-text --testnet-magic 42 --address "${genesis_address}" > /tmp/genesis_utxo.txt
219-
216+
220217
# Check if we got any UTXOs (more than just header lines)
221218
utxo_count=$(cat /tmp/genesis_utxo.txt | /busybox awk 'NR>2 { count++ } END { print count+0 }')
222219
if [ "$utxo_count" -gt 0 ]; then
223220
echo "Found $utxo_count UTXO(s)"
224221
break
225222
fi
226-
223+
227224
echo "No UTXOs found yet, waiting 2 seconds..."
228225
sleep 2
229226
done
@@ -243,42 +240,48 @@ if [ -z "$tx_in1" ] || [ "$tx_in1" = "#" ]; then
243240
exit 1
244241
fi
245242

243+
cardano-cli latest query protocol-parameters \
244+
--socket-path /data/node.socket \
245+
--testnet-magic 42 \
246+
--out-file protocol-parameters.json
247+
246248
# Define output amounts
247249
tx_out1=1000000000 # new_address utxo 1
248250
tx_out2=1000000000 # new_address utxo 2
249251
tx_out3=1000000000 # partner-chains-node-4 (dave)
250252
tx_out4=1000000000 # partner-chains-node-5 (eve)
251253
tx_out5=1000000000 # one-shot-council
252254
tx_out6=1000000000 # one-shot-technical-committee
253-
tx_out8=1000000000 # one-shot-federated-ops
255+
tx_out7=1000000000 # one-shot-federated-ops
254256
tx_out5_lovelace=10000000
255-
tx_out5_reward_token="1000000 $reward_token_policy_id.$reward_token_asset_name"
256-
tx_out7=10000000
257+
tx_out5_token="1000000 $test_cnight_policy_id."
257258

258259
# Total output without fee
259-
total_output=$((tx_out1 + tx_out2 + tx_out3 + tx_out4 + tx_out5_lovelace + tx_out5 + tx_out6 + tx_out7 + tx_out8))
260+
total_output=$((tx_out1 + tx_out2 + tx_out3 + tx_out4 + tx_out5_lovelace + tx_out5 + tx_out6 + tx_out7))
260261

261-
fee=1000000
262+
fee=2000000
262263

263264
# Calculate remaining balance to return to the genesis address
264265
change=$((tx_in_amount - total_output - fee))
265266

266267
# Build the raw transaction
267268
cardano-cli latest transaction build-raw \
269+
--protocol-params-file protocol-parameters.json \
268270
--tx-in $tx_in1 \
269271
--tx-out "$new_address+$tx_out1" \
270272
--tx-out "$new_address+$tx_out2" \
271273
--tx-out "$dave_address+$tx_out3" \
272274
--tx-out "$new_address+$tx_out5" \
273275
--tx-out "$new_address+$tx_out6" \
274-
--tx-out "$new_address+$tx_out8" \
276+
--tx-out "$new_address+$tx_out7" \
275277
--tx-out "$eve_address+$tx_out4" \
276278
--tx-out "$new_address+$change" \
277-
--tx-out "$new_address+$tx_out5_lovelace+$tx_out5_reward_token" \
278-
--tx-out "$vfunction_address+$tx_out7" \
279-
--tx-out-reference-script-file /shared/v-function.script \
280-
--minting-script-file /shared/reward_token_policy.script \
281-
--mint "$tx_out5_reward_token" \
279+
--tx-out "$new_address+$tx_out5_lovelace+$tx_out5_token" \
280+
--tx-in-collateral $tx_in1 \
281+
--mint "$tx_out5_token" \
282+
--mint-script-file /shared/test_cnight.script \
283+
--mint-redeemer-value '{"constructor": 0, "fields": []}' \
284+
--mint-execution-units '(10000000000, 14000000)' \
282285
--fee $fee \
283286
--out-file /data/tx.raw
284287

local-environment/src/networks/local-env/configurations/cardano/reward_token_policy.script

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cborHex":"585501010029800aba2aba1aab9eab9cab9a4888896600330013371e6e50dd99802180298019baa006488100a50a514005149a2a660049211856616c696461746f722072657475726e65642066616c7365001365640041",
3+
"description": "The same policy as used in e2e tests",
4+
"type":"PlutusScriptV3"
5+
}

local-environment/src/networks/local-env/configurations/cardano/v-function.script

Lines changed: 0 additions & 5 deletions
This file was deleted.

local-environment/src/networks/local-env/docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ services:
2525
- ./configurations/cardano/keys/owner-utxo.skey:/keys/owner-utxo.skey
2626
- ./configurations/cardano/keys/owner-utxo.vkey:/keys/owner-utxo.vkey
2727
- ./configurations/cardano/keys/op.cert:/keys/node.cert
28-
- ./configurations/cardano/reward_token_policy.script:/shared/reward_token_policy.script
29-
- ./configurations/cardano/v-function.script:/shared/v-function.script
28+
- ./configurations/cardano/test_cnight.script:/shared/test_cnight.script
3029
- ./configurations/cardano/config-pool1.json:/shared/node-1-config.json.base
3130
- ./configurations/db-sync/config.json:/shared/db-sync-config.json.base
3231
- ./configurations/genesis/byron/genesis.json:/shared/byron/genesis.json.base

partner-chains/toolkit/smart-contracts/offchain/src/test_values.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use cardano_serialization_lib::{Address, Language, PlutusData};
77
use hex_literal::hex;
88
use ogmios_client::{
99
query_ledger_state::{
10-
PlutusCostModels, ProtocolParametersResponse, ReferenceScriptsCosts, ScriptExecutionPrices,
10+
PlutusCostModels, ProtocolParametersResponse, ReferenceScriptsCosts,
11+
ScriptExecutionPriceLimits, ScriptExecutionPrices,
1112
},
1213
types::{NativeScript, OgmiosBytesSize, OgmiosScript, OgmiosTx, OgmiosUtxo, OgmiosValue},
1314
};
@@ -92,6 +93,16 @@ pub(crate) fn protocol_parameters() -> ProtocolParametersResponse {
9293
stake_credential_deposit: OgmiosValue::new_lovelace(2000000),
9394
max_value_size: OgmiosBytesSize { bytes: 5000 },
9495
max_transaction_size: OgmiosBytesSize { bytes: 16384 },
96+
max_block_body_size: OgmiosBytesSize { bytes: 65500 },
97+
max_block_header_size: OgmiosBytesSize { bytes: 1200 },
98+
max_execution_units_per_block: ScriptExecutionPriceLimits {
99+
memory: 62000000,
100+
cpu: 40000000000,
101+
},
102+
max_execution_units_per_transaction: ScriptExecutionPriceLimits {
103+
memory: 14000000,
104+
cpu: 10000000000,
105+
},
95106
min_utxo_deposit_coefficient: 4310,
96107
script_execution_prices: ScriptExecutionPrices {
97108
memory: fraction::Ratio::new_raw(577, 10000),
@@ -105,6 +116,7 @@ pub(crate) fn protocol_parameters() -> ProtocolParametersResponse {
105116
max_collateral_inputs: 3,
106117
collateral_percentage: 150,
107118
min_fee_reference_scripts: ReferenceScriptsCosts { base: 15.0 },
119+
min_stake_pool_cost: OgmiosValue::new_lovelace(0),
108120
}
109121
}
110122

partner-chains/toolkit/utils/ogmios-client/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub trait OgmiosClient {
4444
) -> Result<T, OgmiosClientError>;
4545
}
4646

47-
#[derive(Clone)]
47+
#[derive(Clone, Debug)]
4848
/// Enum representing the parameters for a JSON-RPC request to the Ogmios server.
4949
pub enum OgmiosParams {
5050
/// Represents positional parameters.

0 commit comments

Comments
 (0)