Skip to content

Commit 347352c

Browse files
authored
Merge pull request #26 from SolarRepublic/chore/upgrade-test-suite
Chore/upgrade test suite
2 parents 6b88eca + e95ec5e commit 347352c

19 files changed

+125
-198
lines changed

Makefile

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
SECRETCLI = docker exec -it secretdev /usr/bin/secretcli
22

3+
SECRET_GRPC_PORT ?= 9090
4+
SECRET_LCD_PORT ?= 1317
5+
SECRET_RPC_PORT ?= 26657
6+
LOCALSECRET_VERSION ?= v1.15.0
7+
38
.PHONY: all
49
all: clippy test
510

@@ -70,7 +75,7 @@ compile-optimized-reproducible:
7075
docker run --rm -v "$$(pwd)":/contract \
7176
--mount type=volume,source="$$(basename "$$(pwd)")_cache",target=/code/target \
7277
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
73-
enigmampc/secret-contract-optimizer:1.0.10
78+
ghcr.io/scrtlabs/secret-contract-optimizer:1.0.11
7479

7580
contract.wasm.gz: contract.wasm
7681
cat ./contract.wasm | gzip -9 > ./contract.wasm.gz
@@ -81,9 +86,14 @@ contract.wasm:
8186
.PHONY: start-server
8287
start-server: # CTRL+C to stop
8388
docker run -it --rm \
84-
-p 9091:9091 -p 26657:26657 -p 26656:26656 -p 1317:1317 -p 5000:5000 \
89+
-e FAST_BLOCKS=true \
90+
-p $(SECRET_RPC_PORT):26657 \
91+
-p $(SECRET_LCD_PORT):1317 \
92+
-p $(SECRET_GRPC_PORT):9090 \
93+
-p 5000:5000 \
8594
-v $$(pwd):/root/code \
86-
--name secretdev docker pull ghcr.io/scrtlabs/localsecret:v1.13.1
95+
--name secretdev \
96+
ghcr.io/scrtlabs/localsecret:$(LOCALSECRET_VERSION)
8797

8898
.PHONY: schema
8999
schema:

src/contract.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::dwb::{DelayedWriteBuffer, DWB};
2222
use crate::btbe::initialize_btbe;
2323

2424
#[cfg(feature = "gas_tracking")]
25-
use crate::gas_tracker::{GasTracker, LoggingExt};
25+
use crate::gas_tracker::GasTracker;
2626
#[cfg(feature = "gas_evaporation")]
2727
use crate::msg::Evaporator;
2828
use crate::msg::{

src/dwb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl DelayedWriteBuffer {
178178
matched_index
179179
}
180180

181-
pub fn add_recipient(
181+
pub fn add_recipient<'a>(
182182
&mut self,
183183
store: &mut dyn Storage,
184184
rng: &mut ContractPrng,

src/execute_deposit_redeem.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::dwb::DWB;
88
use crate::msg::{ExecuteAnswer, ResponseStatus::Success};
99
use crate::state::{safe_add, CONFIG, TOTAL_SUPPLY};
1010
use crate::transaction_history::{store_deposit_action, store_redeem_action};
11+
#[cfg(feature = "gas_tracking")]
12+
use crate::gas_tracker::GasTracker;
1113

1214
// deposit functions
1315

@@ -67,7 +69,7 @@ pub fn try_deposit(
6769
let resp = Response::new().set_data(to_binary(&ExecuteAnswer::Deposit { status: Success })?);
6870

6971
#[cfg(feature = "gas_tracking")]
70-
return Ok(resp.add_gas_tracker(tracker));
72+
return Ok(tracker.add_to_response(resp));
7173

7274
#[cfg(not(feature = "gas_tracking"))]
7375
Ok(resp)

src/execute_mint_burn.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use crate::state::{
1717
safe_add, MintersStore, CONFIG, INTERNAL_SECRET_SENSITIVE, NOTIFICATIONS_ENABLED, TOTAL_SUPPLY,
1818
};
1919
use crate::transaction_history::{store_burn_action, store_mint_action};
20+
#[cfg(feature = "gas_tracking")]
21+
use crate::gas_tracker::GasTracker;
2022

2123
// mint functions
2224

@@ -94,7 +96,7 @@ pub fn try_mint(
9496
}
9597

9698
#[cfg(feature = "gas_tracking")]
97-
return Ok(resp.add_gas_tracker(tracker));
99+
return Ok(tracker.add_to_response(resp));
98100

99101
#[cfg(not(feature = "gas_tracking"))]
100102
Ok(resp)

src/execute_transfer_send.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use crate::receiver::Snip20ReceiveMsg;
1717
use crate::state::{ReceiverHashStore, CONFIG, INTERNAL_SECRET_SENSITIVE, NOTIFICATIONS_ENABLED};
1818
use crate::strings::SEND_TO_CONTRACT_ERR_MSG;
1919
use crate::transaction_history::store_transfer_action;
20+
#[cfg(feature = "gas_tracking")]
21+
use crate::gas_tracker::GasTracker;
2022

2123
// transfer functions
2224

@@ -89,7 +91,7 @@ pub fn try_transfer(
8991
group1.log("rest");
9092

9193
#[cfg(feature = "gas_tracking")]
92-
return Ok(resp.add_gas_tracker(tracker));
94+
return Ok(tracker.add_to_response(resp));
9395

9496
#[cfg(not(feature = "gas_tracking"))]
9597
Ok(resp)
@@ -190,7 +192,7 @@ pub fn try_batch_transfer(
190192
}
191193

192194
#[cfg(feature = "gas_tracking")]
193-
return Ok(resp.add_gas_tracker(tracker));
195+
return Ok(tracker.add_to_response(resp));
194196

195197
#[cfg(not(feature = "gas_tracking"))]
196198
Ok(resp)
@@ -383,7 +385,7 @@ pub fn try_send(
383385
}
384386

385387
#[cfg(feature = "gas_tracking")]
386-
return Ok(resp.add_gas_tracker(tracker));
388+
return Ok(tracker.add_to_response(resp));
387389

388390
#[cfg(not(feature = "gas_tracking"))]
389391
Ok(resp)

src/gas_tracker.rs

-10
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ impl<'a> GasTracker<'a> {
4040
}
4141
}
4242

43-
pub trait LoggingExt {
44-
fn add_gas_tracker(&self, tracker: GasTracker) -> Response;
45-
}
46-
47-
impl LoggingExt for Response {
48-
fn add_gas_tracker(&self, tracker: GasTracker) -> Response {
49-
tracker.add_to_response(self.to_owned())
50-
}
51-
}
52-
5343
pub struct GasGroup<'a, 'b> {
5444
pub tracker: &'b mut GasTracker<'a>,
5545
pub name: String,

tests/dwb/.env.example

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
# enabling DEV will print every query/execution to the chain
2+
# DEV=1
3+
NODE_ENV=development
14
SECRET_LCD=http://localhost:1317
25
SECRET_RPC=http://localhost:26657
36
SECRET_CHAIN=secretdev-1
4-
ENABLE_EVAPORATION_TESTS=1
7+
CONTRACT_PATH=../../contract.wasm.gz
8+
9+
# Secret's evaporation API is currently broken
10+
# ENABLE_EVAPORATION_TESTS=1

tests/dwb/.eslintrc.cjs

-14
This file was deleted.

tests/dwb/bun.lockb

7.7 KB
Binary file not shown.

tests/dwb/eslint.config.mjs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import elite from '@blake.regalia/eslint-config-elite';
2+
3+
export default [
4+
...elite,
5+
{
6+
languageOptions: {
7+
ecmaVersion: 2022,
8+
sourceType: 'module',
9+
10+
parserOptions: {
11+
tsconfigRootDir: import.meta.dirname,
12+
project: 'tsconfig.json',
13+
},
14+
},
15+
rules: {
16+
'no-console': 'off',
17+
'@typescript-eslint/naming-convention': 'off',
18+
},
19+
},
20+
];

tests/dwb/package.json

+15-14
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@
44
"scripts": {
55
"build": "tsc && tsc-esm-fix --tsconfig tsconfig.tsc-esm-fix.json --target=dist",
66
"make": "pushd ../../ && make compile-integration && popd",
7-
"test": "bun run make && NODE_ENV=development bun run src/main.ts"
7+
"simulate": "bun run --env-file=.env src/main.ts",
8+
"test": "bun run make && bun run simulate"
89
},
910
"devDependencies": {
10-
"@blake.regalia/belt": "^0.38.1",
11-
"@blake.regalia/eslint-config-elite": "^0.4.4",
11+
"@blake.regalia/belt": "^0.52.1",
12+
"@blake.regalia/eslint-config-elite": "^0.5.11",
1213
"@blake.regalia/tsconfig": "^0.2.0",
13-
"@solar-republic/types": "^0.2.12",
14-
"@types/chai": "^4.3.17",
15-
"@types/node": "^22.1.0",
16-
"chai": "^5.1.1",
14+
"@solar-republic/types": "^0.3.7",
15+
"@types/chai": "^5.0.1",
16+
"@types/node": "^22.10.5",
17+
"chai": "^5.1.2",
1718
"chai-bites": "^0.2.0",
18-
"eslint": " 8",
19-
"tsc-esm-fix": "^3.0.1",
20-
"typescript": "^5.5.4"
19+
"eslint": "9",
20+
"tsc-esm-fix": "^3.1.2",
21+
"typescript": "^5.7.2"
2122
},
2223
"dependencies": {
23-
"@solar-republic/contractor": "^0.8.17",
24-
"@solar-republic/cosmos-grpc": "^0.17.1",
25-
"@solar-republic/crypto": "^0.2.14",
26-
"@solar-republic/neutrino": "^1.5.3",
24+
"@solar-republic/contractor": "^0.10.3",
25+
"@solar-republic/cosmos-grpc": "^0.17.2",
26+
"@solar-republic/crypto": "^0.3.2",
27+
"@solar-republic/neutrino": "^1.8.5",
2728
"bignumber.js": "^9.1.2"
2829
}
2930
}

tests/dwb/src/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const [k_wallet_a, k_wallet_b, k_wallet_c, k_wallet_d] = await Promise.al
1616
'buqil+tLeeW7VLuugvOdTmkP3+tUwlCoScPZxeteBPE=',
1717
'UFrCdmofR9iChp6Eg7kE5O3wT+jsOXwJPWwB6kSeuhE=',
1818
'MM/1ZSbT5RF1BnaY6ui/i7yEN0mukGzvXUv+jOyjD0E=',
19-
].map(sb64_sk => Wallet(base64_to_bytes(sb64_sk), SI_SECRET_CHAIN, P_SECRET_LCD, P_SECRET_RPC, 'secret')));
19+
].map(sb64_sk => Wallet(base64_to_bytes(sb64_sk), SI_SECRET_CHAIN, P_SECRET_LCD, P_SECRET_RPC, [X_GAS_PRICE, 'uscrt'], 'secret')));
2020

2121
export const H_ADDRS = {
2222
[k_wallet_a.addr]: 'Alice',

tests/dwb/src/contract.ts

+6-97
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,18 @@
1-
import type {JsonObject} from '@blake.regalia/belt';
21
import type {EncodedGoogleProtobufAny} from '@solar-republic/cosmos-grpc/google/protobuf/any';
3-
import type {TxResultTuple, Wallet, WeakSecretAccAddr} from '@solar-republic/neutrino';
4-
import type {CwHexLower, WeakUintStr} from '@solar-republic/types';
2+
import type {TxResponseTuple, Wallet} from '@solar-republic/neutrino';
53

6-
import {promisify} from 'node:util';
7-
import {gunzip} from 'node:zlib';
4+
import {TendermintEventFilter, broadcast_result, create_and_sign_tx_direct} from '@solar-republic/neutrino';
85

9-
import {base64_to_bytes, bytes_to_hex, bytes_to_text, cast, sha256} from '@blake.regalia/belt';
10-
import {queryCosmosBankBalance} from '@solar-republic/cosmos-grpc/cosmos/bank/v1beta1/query';
11-
import {encodeGoogleProtobufAny} from '@solar-republic/cosmos-grpc/google/protobuf/any';
12-
import {SI_MESSAGE_TYPE_SECRET_COMPUTE_MSG_STORE_CODE, SI_MESSAGE_TYPE_SECRET_COMPUTE_MSG_INSTANTIATE_CONTRACT, encodeSecretComputeMsgStoreCode, encodeSecretComputeMsgInstantiateContract} from '@solar-republic/cosmos-grpc/secret/compute/v1beta1/msg';
13-
import {querySecretComputeCodeHashByCodeId, querySecretComputeCodes} from '@solar-republic/cosmos-grpc/secret/compute/v1beta1/query';
14-
import {destructSecretRegistrationKey} from '@solar-republic/cosmos-grpc/secret/registration/v1beta1/msg';
15-
import {querySecretRegistrationTxKey} from '@solar-republic/cosmos-grpc/secret/registration/v1beta1/query';
16-
import {SecretWasm, TendermintEventFilter, TendermintWs, broadcast_result, create_and_sign_tx_direct, exec_fees} from '@solar-republic/neutrino';
17-
18-
import {X_GAS_PRICE, P_SECRET_LCD, P_SECRET_RPC} from './constants';
6+
import {P_SECRET_RPC} from './constants';
197

208
const k_tef = await TendermintEventFilter(P_SECRET_RPC);
219

22-
export async function exec(k_wallet: Wallet, atu8_msg: EncodedGoogleProtobufAny, xg_gas_limit: bigint): Promise<TxResultTuple> {
23-
const [atu8_raw, atu8_signdoc, si_txn] = await create_and_sign_tx_direct(
10+
export async function exec(k_wallet: Wallet, atu8_msg: EncodedGoogleProtobufAny, xg_gas_limit: bigint): Promise<TxResponseTuple> {
11+
const [atu8_raw, sb16_txn, atu8_signdoc] = await create_and_sign_tx_direct(
2412
k_wallet,
2513
[atu8_msg],
26-
exec_fees(xg_gas_limit, X_GAS_PRICE, 'uscrt'),
2714
xg_gas_limit
2815
);
2916

30-
return await broadcast_result(k_wallet, atu8_raw, si_txn, k_tef);
31-
}
32-
33-
export async function upload_code(k_wallet: Wallet, atu8_wasm: Uint8Array): Promise<WeakUintStr> {
34-
let atu8_bytecode = atu8_wasm;
35-
36-
// gzip-encoded; decompress
37-
if(0x1f === atu8_wasm[0] && 0x8b === atu8_wasm[1]) {
38-
atu8_bytecode = await promisify(gunzip)(atu8_wasm);
39-
}
40-
41-
// hash
42-
const atu8_hash = await sha256(atu8_bytecode);
43-
const sb16_hash = cast<CwHexLower>(bytes_to_hex(atu8_hash));
44-
45-
// fetch all uploaded codes
46-
const [,, g_codes] = await querySecretComputeCodes(P_SECRET_LCD);
47-
48-
// already uploaded
49-
const g_existing = g_codes?.code_infos?.find(g => g.code_hash! === sb16_hash);
50-
if(g_existing) {
51-
console.info(`Found code ID ${g_existing.code_id} already uploaded to network`);
52-
53-
return g_existing.code_id as WeakUintStr;
54-
}
55-
56-
// upload
57-
const [xc_code, sx_res, g_meta, atu8_data, h_events] = await exec(k_wallet, encodeGoogleProtobufAny(
58-
SI_MESSAGE_TYPE_SECRET_COMPUTE_MSG_STORE_CODE,
59-
encodeSecretComputeMsgStoreCode(
60-
k_wallet.addr,
61-
atu8_bytecode
62-
)
63-
), 30_000000n);
64-
65-
if(xc_code) throw Error(sx_res);
66-
67-
return h_events!['message.code_id'][0] as WeakUintStr;
68-
}
69-
70-
export async function instantiate_contract(k_wallet: Wallet, sg_code_id: WeakUintStr, h_init_msg: JsonObject): Promise<WeakSecretAccAddr> {
71-
const [,, g_reg] = await querySecretRegistrationTxKey(P_SECRET_LCD);
72-
const [atu8_cons_pk] = destructSecretRegistrationKey(g_reg!);
73-
const k_wasm = SecretWasm(atu8_cons_pk!);
74-
const [,, g_hash] = await querySecretComputeCodeHashByCodeId(P_SECRET_LCD, sg_code_id);
75-
76-
// @ts-expect-error imported types versioning
77-
const atu8_body = await k_wasm.encodeMsg(g_hash!.code_hash, h_init_msg);
78-
79-
const [xc_code, sx_res, g_meta, atu8_data, h_events] = await exec(k_wallet, encodeGoogleProtobufAny(
80-
SI_MESSAGE_TYPE_SECRET_COMPUTE_MSG_INSTANTIATE_CONTRACT,
81-
encodeSecretComputeMsgInstantiateContract(
82-
k_wallet.addr,
83-
null,
84-
sg_code_id,
85-
h_init_msg['name'] as string,
86-
atu8_body
87-
)
88-
), 10_000_000n);
89-
90-
if(xc_code) {
91-
const s_error = g_meta?.log ?? sx_res;
92-
93-
// encrypted error message
94-
const m_response = /(\d+):(?: \w+:)*? encrypted: (.+?): (.+?) contract/.exec(s_error);
95-
if(m_response) {
96-
// destructure match
97-
const [, s_index, sb64_encrypted, si_action] = m_response;
98-
99-
// decrypt ciphertext
100-
const atu8_plaintext = await k_wasm.decrypt(base64_to_bytes(sb64_encrypted), atu8_body.slice(0, 32));
101-
102-
throw Error(bytes_to_text(atu8_plaintext));
103-
}
104-
105-
throw Error(sx_res);
106-
}
107-
108-
return h_events!['message.contract_address'][0] as WeakSecretAccAddr;
17+
return await broadcast_result(k_wallet, atu8_raw, sb16_txn, k_tef);
10918
}

tests/dwb/src/dwb-entry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {Nilable} from '@blake.regalia/belt';
2-
import type {CwSecretAccAddr} from '@solar-republic/neutrino';
2+
import type {CwSecretAccAddr} from '@solar-republic/types';
33

44
import {bytes_to_biguint_be, bytes_to_hex} from '@blake.regalia/belt';
55
import {bech32_encode} from '@solar-republic/crypto';

0 commit comments

Comments
 (0)