From e76102c024c34790401f784dcdd3bcb654017e09 Mon Sep 17 00:00:00 2001 From: Nick DeLuca Date: Wed, 3 Apr 2024 22:40:10 +0000 Subject: [PATCH] add configuration for using construction test locally --- rosetta-cli-conf/kava-localnet/config.json | 20 +++- rosetta-cli-conf/kava-localnet/kava.ros | 133 +++++++++++++++++++++ services/construction_payloads.go | 4 +- 3 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 rosetta-cli-conf/kava-localnet/kava.ros diff --git a/rosetta-cli-conf/kava-localnet/config.json b/rosetta-cli-conf/kava-localnet/config.json index 67d0d73..7c2d20d 100644 --- a/rosetta-cli-conf/kava-localnet/config.json +++ b/rosetta-cli-conf/kava-localnet/config.json @@ -6,7 +6,7 @@ "online_url": "http://localhost:8000", "data_directory": "", "http_timeout": 10, - "max_retries": 5, + "max_retries": 25, "retry_elapsed_time": 0, "max_online_connections": 120, "max_sync_concurrency": 5, @@ -15,7 +15,23 @@ "log_configuration": false, "compression_disabled": false, "memory_limit_disabled": false, - "construction": null, + "construction": { + "offline_url": "http://localhost:8001", + "max_offline_connections": 100, + "force_retry": true, + "stale_depth": 5, + "broadcast_limit": 5, + "ignore_broadcast_failures": false, + "clear_broadcasts": false, + "prefunded_accounts": [], + "constructor_dsl_file": "kava.ros", + "end_conditions": { + "create_account": 10, + "transfer": 10 + }, + "quiet": false, + "initial_balance_fetch_disabled": false + }, "data": { "active_reconciliation_concurrency": 16, "inactive_reconciliation_concurrency": 4, diff --git a/rosetta-cli-conf/kava-localnet/kava.ros b/rosetta-cli-conf/kava-localnet/kava.ros new file mode 100644 index 0000000..0af2277 --- /dev/null +++ b/rosetta-cli-conf/kava-localnet/kava.ros @@ -0,0 +1,133 @@ +request_funds(1){ + find_account{ + currency = {"symbol":"KAVA", "decimals":6}; + random_account = find_balance({ + "minimum_balance": { + "value": "0", + "currency": {{currency}} + }, + "create_limit":1 + }); + }, + request{ + loaded_account = find_balance({ + "account_identifier": {{random_account.account_identifier}}, + "minimum_balance":{ + "value": "1000000", + "currency": {{currency}} + } + }); + } +} + +create_account(1){ + create{ + network = set_variable({"network":"kava-localnet", "blockchain":"Kava"}); + key = generate_key({"curve_type": "secp256k1"}); + account = derive({ + "network_identifier": {{network}}, + "public_key": {{key.public_key}} + }); + save_account({ + "account_identifier": {{account.account_identifier}}, + "keypair": {{key}} + }); + } +} + +transfer(10){ + transfer{ + transfer.network = set_variable({"network":"kava-localnet", "blockchain":"Kava"}); + currency = {"symbol":"KAVA", "decimals":6}; + sender = find_balance({ + "minimum_balance":{ + "value": "100000", + "currency": {{currency}} + } + }); + + // Set the recipient_amount as some value <= sender.balance-max_fee + max_fee = "1000"; + available_amount = {{sender.balance.value}} - {{max_fee}}; + recipient_amount = random_number({"minimum": "1", "maximum": {{available_amount}}}); + print_message({"recipient_amount":{{recipient_amount}}}); + + // Find recipient and construct operations + sender_amount = 0 - {{recipient_amount}}; + recipient = find_balance({ + "not_account_identifier":[{{sender.account_identifier}}], + "minimum_balance":{ + "value": "0", + "currency": {{currency}} + }, + "create_limit": 100, + "create_probability": 50 + }); + transfer.confirmation_depth = "1"; + transfer.operations = [ + { + "operation_identifier":{"index":0}, + "type":"transfer", + "account":{{sender.account_identifier}}, + "amount":{ + "value":{{sender_amount}}, + "currency":{{currency}} + } + }, + { + "operation_identifier":{"index":1}, + "related_operations":[{"index":0}], + "type":"transfer", + "account":{{recipient.account_identifier}}, + "amount":{ + "value":{{recipient_amount}}, + "currency":{{currency}} + } + } + ]; + } +} + +return_funds(10){ + transfer{ + transfer.network = set_variable({"network":"kava-localnet", "blockchain":"Kava"}); + currency = {"symbol":"KAVA", "decimals":6}; + max_fee = "1000"; + sender = find_balance({ + "minimum_balance":{ + "value": {{max_fee}}, + "currency": {{currency}} + } + }); + + // Set the recipient_amount as some sender.balance-max_fee + available_amount = {{sender.balance.value}} - {{max_fee}}; + print_message({"available_amount":{{available_amount}}}); + sender_amount = 0 - {{available_amount}}; + + // Provide a static address as the recipient and construct operations + faucet = {"address":"kava1vlpsrmdyuywvaqrv7rx6xga224sqfwz3fyfhwq"}; + transfer.confirmation_depth = "1"; + transfer.operations = [ + { + "operation_identifier":{"index":0}, + "type":"transfer", + "account":{{sender.account_identifier}}, + "amount":{ + "value":{{sender_amount}}, + "currency":{{currency}} + } + }, + { + "operation_identifier":{"index":1}, + "related_operations":[{"index":0}], + "type":"transfer", + "account":{{faucet}}, + "amount":{ + "value":{{available_amount}}, + "currency":{{currency}} + } + } + ]; + } +} diff --git a/services/construction_payloads.go b/services/construction_payloads.go index 68effba..874ff1c 100644 --- a/services/construction_payloads.go +++ b/services/construction_payloads.go @@ -26,11 +26,11 @@ import ( sdkmath "cosmossdk.io/math" "github.com/coinbase/rosetta-sdk-go/types" + "github.com/cometbft/cometbft/crypto" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - "github.com/cometbft/cometbft/crypto" ) var requiredMetadata = []string{ @@ -116,6 +116,8 @@ func (s *ConstructionAPIService) ConstructionPayloads( chainID = "kava_2222-10" case "kava-testnet": chainID = "kava_2221-16000" + case "kava-localnet": + chainID = "kavalocalnet_8888-1" } signerData := authsigning.SignerData{