Skip to content

Commit

Permalink
test: refactor (#26)
Browse files Browse the repository at this point in the history
* test: refactor

* fix: test
  • Loading branch information
MiniFrenchBread authored Oct 14, 2024
1 parent cbb23b3 commit 892efd4
Show file tree
Hide file tree
Showing 40 changed files with 711 additions and 307 deletions.
3 changes: 2 additions & 1 deletion node/storage_with_stream/src/store/store_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ impl StreamWrite for StoreManager {
}

impl StoreManager {
pub async fn memorydb(config: LogConfig,
pub async fn memorydb(
config: LogConfig,
executor: task_executor::TaskExecutor,
) -> Result<Self> {
let stream_store = StreamStore::new_in_memory().await?;
Expand Down
3 changes: 2 additions & 1 deletion node/stream/src/stream_manager/stream_data_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ async fn download_with_proof(
while fail_cnt < clients.len() {
// find next
let seg_index = start_index / ENTRIES_PER_SEGMENT;
let flow_seg_index = (tx.transaction.start_entry_index as usize + start_index) / ENTRIES_PER_SEGMENT;
let flow_seg_index =
(tx.transaction.start_entry_index as usize + start_index) / ENTRIES_PER_SEGMENT;
let mut try_cnt = 0;
loop {
let configs = shard_configs.read().await;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
95 changes: 0 additions & 95 deletions tests/config/0gchain-init-genesis-mac.sh

This file was deleted.

33 changes: 24 additions & 9 deletions tests/config/0gchain-init-genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ jq --version >/dev/null 2>&1 || sudo snap install jq -y

mkdir -p $ROOT_DIR

SED_I="sed -i"
OS_NAME=`uname -o`
if [[ "$OS_NAME" = "Darwin" ]]; then
SED_I="sed -i ''"
fi

# Init configs
for ((i=0; i<$NUM_NODES; i++)) do
$BINARY init node$i --home $ROOT_DIR/node$i --chain-id $CHAIN_ID
Expand All @@ -22,10 +28,10 @@ for ((i=0; i<$NUM_NODES; i++)) do
TMP_GENESIS=$ROOT_DIR/node$i/config/tmp_genesis.json

# Replace stake with neuron
sed -in-place='' 's/stake/ua0gi/g' "$GENESIS"
$SED_I 's/"stake"/"ua0gi"/g' "$GENESIS"

# Replace the default evm denom of aphoton with neuron
sed -in-place='' 's/aphoton/neuron/g' "$GENESIS"
$SED_I 's/aphoton/neuron/g' "$GENESIS"

cat $GENESIS | jq '.consensus_params.block.max_gas = "25000000"' >$TMP_GENESIS && mv $TMP_GENESIS $GENESIS

Expand Down Expand Up @@ -53,15 +59,24 @@ for ((i=0; i<$NUM_NODES; i++)) do

# Change app.toml
APP_TOML=$ROOT_DIR/node$i/config/app.toml
sed -i 's/minimum-gas-prices = "0ua0gi"/minimum-gas-prices = "1000000000neuron"/' $APP_TOML
sed -i '/\[grpc\]/,/^\[/ s/enable = true/enable = false/' $APP_TOML
sed -i '/\[grpc-web\]/,/^\[/ s/enable = true/enable = false/' $APP_TOML
sed -i '/\[json-rpc\]/,/^\[/ s/enable = false/enable = true/' $APP_TOML
$SED_I 's/minimum-gas-prices = "0ua0gi"/minimum-gas-prices = "1000000000neuron"/' $APP_TOML
$SED_I '/\[grpc\]/,/^\[/ s/enable = true/enable = false/' $APP_TOML
$SED_I '/\[grpc-web\]/,/^\[/ s/enable = true/enable = false/' $APP_TOML
$SED_I '/\[json-rpc\]/,/^\[/ s/enable = false/enable = true/' $APP_TOML

# Change config.toml
CONFIG_TOML=$ROOT_DIR/node$i/config/config.toml
sed -i '/seeds = /c\seeds = ""' $CONFIG_TOML
sed -i 's/addr_book_strict = true/addr_book_strict = false/' $CONFIG_TOML
# $SED_I '/seeds = /c\seeds = ""' $CONFIG_TOML
$SED_I 's/addr_book_strict = true/addr_book_strict = false/' $CONFIG_TOML

# Change block time to very small
$SED_I 's/timeout_propose = "3s"/timeout_propose = "300ms"/' $CONFIG_TOML
$SED_I 's/timeout_propose_delta = "500ms"/timeout_propose_delta = "50ms"/' $CONFIG_TOML
$SED_I 's/timeout_prevote = "1s"/timeout_prevote = "100ms"/' $CONFIG_TOML
$SED_I 's/timeout_prevote_delta = "500ms"/timeout_prevote_delta = "50ms"/' $CONFIG_TOML
$SED_I 's/timeout_precommit = "1s"/timeout_precommit = "100ms"/' $CONFIG_TOML
$SED_I 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "50ms"/' $CONFIG_TOML
$SED_I 's/timeout_commit = "5s"/timeout_commit = "500ms"/' $CONFIG_TOML
done

# Update persistent_peers in config.toml
Expand All @@ -73,7 +88,7 @@ for ((i=1; i<$NUM_NODES; i++)) do
P2P_PORT=$(($P2P_PORT_START+$j))
PERSISTENT_NODES=$PERSISTENT_NODES$NODE_ID@127.0.0.1:$P2P_PORT
done
sed -i "/persistent_peers = /c\persistent_peers = \"$PERSISTENT_NODES\"" $ROOT_DIR/node$i/config/config.toml
$SED_I "s/persistent_peers = \"\"/persistent_peers = \"$PERSISTENT_NODES\"/" $ROOT_DIR/node$i/config/config.toml
done

# Create genesis with a single validator
Expand Down
28 changes: 23 additions & 5 deletions tests/config/node_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
ZGS_CONFIG = {
"log_config_file": "log_config",
"confirmation_block_count": 1,
}

KV_CONFIG = {
"log_config_file": "log_config",
"confirmation_block_count": 1,
"router": {
"private_ip_enabled": True,
},
"sync": {
"heartbeat_interval": "1s",
"peer_connect_timeout": "3s",
"peer_disconnect_timeout": "3s",
"peer_find_timeout": "3s",
"peer_chunks_download_timeout": "3s",
"auto_sync_idle_interval": "1s",
"sequential_find_peer_timeout": "10s",
"random_find_peer_timeout": "10s",
}
}

BSC_CONFIG = dict(
Expand Down Expand Up @@ -55,3 +63,13 @@

NO_SEAL_FLAG = 0x1
NO_MERKLE_PROOF_FLAG = 0x2

def update_config(default: dict, custom: dict):
"""
Supports to update configurations with dict value.
"""
for (key, value) in custom.items():
if default.get(key) is None or type(value) != dict:
default[key] = value
else:
update_config(default[key], value)
18 changes: 4 additions & 14 deletions tests/kv_access_control_test.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
#!/usr/bin/env python3
import base64
from this import d
import time
from os import access
import random
from test_framework.test_framework import TestFramework
from kv_test_framework.test_framework import KVTestFramework
from utility.kv import (
MAX_U64,
op_with_address,
op_with_key,
STREAM_DOMAIN,
with_prefix,
is_access_control_permission_denied,
is_sender_no_write_permission,
is_write_permission_denied,
MAX_STREAM_ID,
pad,
to_key_with_size,
to_stream_id,
create_kv_data,
AccessControlOps,
rand_key,
rand_write,
)
from utility.submission import submit_data
from utility.submission import create_submission
from kv_utility.submission import create_submission
from utility.utils import (
assert_equal,
wait_until,
)
from config.node_config import TX_PARAMS, TX_PARAMS1, GENESIS_ACCOUNT, GENESIS_ACCOUNT1


class KVAccessControlTest(TestFramework):
class KVAccessControlTest(KVTestFramework):
def setup_params(self):
self.num_blockchain_nodes = 1
self.num_nodes = 1
Expand Down Expand Up @@ -66,7 +56,7 @@ def submit(
submissions, data_root = create_submission(
chunk_data, tags if given_tags is None else given_tags
)
self.contract.submit(submissions, tx_params=tx_params)
self.contract.submit(submissions, tx_prarams=tx_params)
wait_until(lambda: self.contract.num_submissions() == self.next_tx_seq + 1)

client = self.nodes[0]
Expand Down
4 changes: 4 additions & 0 deletions tests/kv_config/node_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
KV_CONFIG = {
"log_config_file": "log_config",
"confirmation_block_count": 1,
}
8 changes: 4 additions & 4 deletions tests/kv_data_fetcher_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
import random
from test_framework.test_framework import TestFramework
from kv_test_framework.test_framework import KVTestFramework
from utility.kv import (
MAX_U64,
MAX_STREAM_ID,
Expand All @@ -9,7 +9,7 @@
rand_write,
)
from utility.submission import submit_data
from utility.submission import create_submission
from kv_utility.submission import create_submission
from utility.utils import (
assert_equal,
rpc_port,
Expand All @@ -18,7 +18,7 @@
from config.node_config import TX_PARAMS, TX_PARAMS1, GENESIS_ACCOUNT, GENESIS_ACCOUNT1


class DataFetcherTest(TestFramework):
class DataFetcherTest(KVTestFramework):
def setup_params(self):
self.num_blockchain_nodes = 1
self.num_nodes = 3
Expand Down Expand Up @@ -70,7 +70,7 @@ def submit(
submissions, data_root = create_submission(
chunk_data, tags if given_tags is None else given_tags
)
self.contract.submit(submissions, tx_params=tx_params)
self.contract.submit(submissions, tx_prarams=tx_params)
wait_until(lambda: self.contract.num_submissions() == self.next_tx_seq + 1)

client = self.nodes[0]
Expand Down
21 changes: 4 additions & 17 deletions tests/kv_iterator_test.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
#!/usr/bin/env python3
import base64
from this import d
import time
from os import access
import random
from test_framework.test_framework import TestFramework
from kv_test_framework.test_framework import KVTestFramework
from utility.kv import (
MAX_U64,
op_with_address,
op_with_key,
STREAM_DOMAIN,
with_prefix,
is_write_permission_denied,
MAX_STREAM_ID,
pad,
to_key_with_size,
to_stream_id,
create_kv_data,
AccessControlOps,
rand_key,
rand_write,
)
from utility.submission import submit_data
from utility.submission import create_submission
from kv_utility.submission import create_submission
from utility.utils import (
assert_equal,
wait_until,
)
from config.node_config import TX_PARAMS, TX_PARAMS1, GENESIS_ACCOUNT, GENESIS_ACCOUNT1


class KVPutGetTest(TestFramework):
class KVPutGetTest(KVTestFramework):
def setup_params(self):
self.num_blockchain_nodes = 1
self.num_nodes = 1
Expand Down Expand Up @@ -70,7 +57,7 @@ def submit(
submissions, data_root = create_submission(
chunk_data, tags if given_tags is None else given_tags
)
self.contract.submit(submissions, tx_params=tx_params)
self.contract.submit(submissions, tx_prarams=tx_params)
wait_until(lambda: self.contract.num_submissions() == self.next_tx_seq + 1)

client = self.nodes[0]
Expand Down
Loading

0 comments on commit 892efd4

Please sign in to comment.