Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove useless test for sol contract #1355

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 13 additions & 42 deletions builtin-contract/metadata/contracts/metadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ contract MetadataManager {
uint64 interval;
}

struct CkbRelatedInfo {
bytes32 metadata_type_id;
bytes32 checkpoint_type_id;
bytes32 xudt_args;
bytes32 stake_smt_type_id;
bytes32 delegate_smt_type_id;
bytes32 reward_smt_type_id;
}

// to store all metadata with epoch as key
mapping(uint64 => Metadata) metadata_set;

Expand Down Expand Up @@ -112,7 +121,7 @@ contract MetadataManager {
}

// update current consensus_config
function updateConsensusConfig(ConsensusConfig memory config) public {
function updateConsensusConfig(ConsensusConfig memory config) public view {
Metadata memory highest_metadata = metadata_set[highest_epoch];

bool find_sender = false;
Expand All @@ -136,45 +145,7 @@ contract MetadataManager {
return metadata;
}

function verifierList() external view returns (address[] memory, uint256) {
uint256 length = metadata_set[highest_epoch].verifier_list.length;
address[] memory verifiers = new address[](length);

for (uint256 i = 0; i < length; ++i) {
verifiers[i] = metadata_set[highest_epoch]
.verifier_list[i]
.address_;
}

return (verifiers, highest_epoch);
}

function isProposer(address verifier) external view returns (bool) {
ValidatorExtend memory proposer;

uint256 length = metadata_set[highest_epoch].verifier_list.length;
for (uint256 i = 0; i < length; ++i) {
if (
metadata_set[highest_epoch].verifier_list[i].propose_weight >
proposer.propose_weight
) {
proposer = metadata_set[highest_epoch].verifier_list[i];
}
}

return verifier == proposer.address_;
}

function isVerifier(address relayer) external view returns (bool) {
uint256 length = metadata_set[highest_epoch].verifier_list.length;
for (uint256 i = 0; i < length; ++i) {
if (
metadata_set[highest_epoch].verifier_list[i].address_ == relayer
) {
return true;
}
}

return false;
}
function setCkbRelatedInfo(
CkbRelatedInfo memory ckbRelatedInfo
) public view {}
}
137 changes: 0 additions & 137 deletions builtin-contract/metadata/test/Metadata.test.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
],
"name": "updateConsensusConfig",
"outputs": [],
"stateMutability": "nonpayable",
"stateMutability": "view",
"type": "function"
},
{
Expand Down
38 changes: 37 additions & 1 deletion core/executor/src/tests/system_script/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ use crate::{
init,
metadata::{
metadata_abi::{self, ConsensusConfig, Metadata, MetadataVersion, ValidatorExtend},
MetadataContract,
MetadataContract, MetadataStore,
},
SystemContract, METADATA_CONTRACT_ADDRESS,
},
tests::{gen_tx, gen_vicinity},
CURRENT_METADATA_ROOT,
};

static ROCKSDB_PATH: &str = "./free-space/system-contract/metadata";
Expand All @@ -38,6 +39,8 @@ fn test_write_functions() {

test_second(&mut backend, &executor);
test_validator(&mut backend, &executor);

test_update_consensus_config(&mut backend, &executor);
}

fn test_init<'a>(backend: &mut MemoryBackend<'a>, executor: &MetadataContract<MemoryBackend<'a>>) {
Expand Down Expand Up @@ -138,6 +141,39 @@ fn prepare_tx_5(addr: &H160) -> SignedTransaction {
gen_tx(*addr, METADATA_CONTRACT_ADDRESS, 1000, data.encode())
}

fn prepare_tx_with_consensus_config(addr: &H160, interval: u64) -> SignedTransaction {
let data = metadata_abi::UpdateConsensusConfigCall {
config: {
let mut config = prepare_metadata().consensus_config;
config.interval = interval;
config
},
};

gen_tx(*addr, METADATA_CONTRACT_ADDRESS, 1000, data.encode())
}

// change consensus interval test
fn test_update_consensus_config<'a>(
backend: &mut MemoryBackend<'a>,
executor: &MetadataContract<MemoryBackend<'a>>,
) {
let interval = 10;
let addr = H160::from_str("0xf000000000000000000000000000000000000000").unwrap();
let tx = prepare_tx_with_consensus_config(&addr, interval);

let r = executor.exec_(backend, &tx);
assert!(r.exit_reason.is_succeed());

let root = CURRENT_METADATA_ROOT.with(|r| *r.borrow());

let store = MetadataStore::new(root).unwrap();

let current_config = store.get_metadata(1).unwrap().consensus_config;

assert_eq!(current_config.interval, interval)
}

fn prepare_metadata() -> Metadata {
Metadata {
version: MetadataVersion {
Expand Down