Skip to content

Commit

Permalink
integrate program version number to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Sep 11, 2024
1 parent d369b6e commit d2f37d4
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 10 deletions.
Binary file modified crates/client/entropy_metadata.scale
Binary file not shown.
3 changes: 3 additions & 0 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ pub async fn sign(
}

/// Store a program on chain and return it's hash
#[allow(clippy::too_many_arguments)]
#[tracing::instrument(
skip_all,
fields(
Expand All @@ -210,12 +211,14 @@ pub async fn store_program(
configuration_interface: Vec<u8>,
auxiliary_data_interface: Vec<u8>,
oracle_data_pointer: Vec<u8>,
version_number: u8,
) -> Result<<EntropyConfig as Config>::Hash, ClientError> {
let set_program_tx = entropy::tx().programs().set_program(
program,
configuration_interface,
auxiliary_data_interface,
oracle_data_pointer,
version_number,
);
let in_block =
submit_transaction_with_pair(api, rpc, deployer_pair, &set_program_tx, None).await?;
Expand Down
2 changes: 2 additions & 0 deletions crates/client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async fn test_store_and_remove_program() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down Expand Up @@ -142,6 +143,7 @@ async fn test_remove_program_reference_counter() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down
61 changes: 53 additions & 8 deletions crates/test-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ enum CliCommand {
/// interface. If no such file exists, it is assumed the program has no configuration
/// interface.
programs: Vec<String>,
/// Option of version numbers to go with the programs, will default to 0 if None
version_numbers: Option<Vec<u8>>,
/// A name or mnemonic from which to derive a program modification keypair.
/// This is used to send the register extrinsic so it must be funded
/// If giving a name it must be preceded with "//", eg: "--mnemonic-option //Alice"
Expand Down Expand Up @@ -109,6 +111,8 @@ enum CliCommand {
/// interface. If no such file exists, it is assumed the program has no configuration
/// interface.
programs: Vec<String>,
/// Option of version numbers to go with the programs, will default to 0 if None
version_numbers: Option<Vec<u8>>,
/// The mnemonic to use for the call
#[arg(short, long)]
mnemonic_option: Option<String>,
Expand All @@ -121,6 +125,8 @@ enum CliCommand {
config_interface_file: Option<PathBuf>,
/// The path to a file containing the program aux interface (defaults to empty)
aux_data_interface_file: Option<PathBuf>,
/// The version number of the program you compiled with
version_number: u8,
/// The mnemonic to use for the call
#[arg(short, long)]
mnemonic_option: Option<String>,
Expand Down Expand Up @@ -183,7 +189,7 @@ pub async fn run_command(
let rpc = get_rpc(&endpoint_addr).await?;

match cli.command {
CliCommand::Register { mnemonic_option, programs } => {
CliCommand::Register { mnemonic_option, programs, version_numbers } => {
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
} else {
Expand All @@ -196,9 +202,22 @@ pub async fn run_command(

let mut programs_info = vec![];

for program in programs {
for (i, program) in programs.into_iter().enumerate() {
let version_number = if let Some(ref version_numbers) = version_numbers {
version_numbers[i]
} else {
0u8
};
programs_info.push(
Program::from_hash_or_filename(&api, &rpc, &program_keypair, program).await?.0,
Program::from_hash_or_filename(
&api,
&rpc,
&program_keypair,
program,
version_number,
)
.await?
.0,
);
}

Expand Down Expand Up @@ -248,6 +267,7 @@ pub async fn run_command(
program_file,
config_interface_file,
aux_data_interface_file,
version_number,
} => {
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
Expand Down Expand Up @@ -284,6 +304,7 @@ pub async fn run_command(
config_interface,
aux_data_interface,
vec![],
version_number,
)
.await?;
Ok(format!("Program stored {hash}"))
Expand All @@ -305,7 +326,12 @@ pub async fn run_command(

Ok("Program removed".to_string())
},
CliCommand::UpdatePrograms { signature_verifying_key, mnemonic_option, programs } => {
CliCommand::UpdatePrograms {
signature_verifying_key,
mnemonic_option,
programs,
version_numbers,
} => {
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
} else {
Expand All @@ -315,9 +341,23 @@ pub async fn run_command(
println!("Program account: {}", program_keypair.public());

let mut programs_info = Vec::new();
for program in programs {

for (i, program) in programs.into_iter().enumerate() {
let version_number = if let Some(ref version_numbers) = version_numbers {
version_numbers[i]
} else {
0u8
};
programs_info.push(
Program::from_hash_or_filename(&api, &rpc, &program_keypair, program).await?.0,
Program::from_hash_or_filename(
&api,
&rpc,
&program_keypair,
program,
version_number,
)
.await?
.0,
);
}

Expand Down Expand Up @@ -459,6 +499,7 @@ impl Program {
rpc: &LegacyRpcMethods<EntropyConfig>,
keypair: &sr25519::Pair,
hash_or_filename: String,
version_number: u8,
) -> anyhow::Result<Self> {
match hex::decode(hash_or_filename.clone()) {
Ok(hash) => {
Expand All @@ -474,10 +515,12 @@ impl Program {
};
Ok(Self::new(H256(hash_32), configuration))
},
Err(_) => Self::from_file(api, rpc, keypair, hash_or_filename).await,
Err(_) => {
Self::from_file(api, rpc, keypair, hash_or_filename, version_number).await
},
}
},
Err(_) => Self::from_file(api, rpc, keypair, hash_or_filename).await,
Err(_) => Self::from_file(api, rpc, keypair, hash_or_filename, version_number).await,
}
}

Expand All @@ -488,6 +531,7 @@ impl Program {
rpc: &LegacyRpcMethods<EntropyConfig>,
keypair: &sr25519::Pair,
filename: String,
version_number: u8,
) -> anyhow::Result<Self> {
let program_bytecode = fs::read(&filename)?;

Expand Down Expand Up @@ -526,6 +570,7 @@ impl Program {
config_description,
auxiliary_data_schema,
vec![],
version_number,
)
.await
{
Expand Down
10 changes: 10 additions & 0 deletions crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ async fn test_signature_requests_fail_on_different_conditions() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down Expand Up @@ -350,6 +351,7 @@ async fn signature_request_with_derived_account_works() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down Expand Up @@ -492,6 +494,7 @@ async fn test_request_limit_are_updated_during_signing() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down Expand Up @@ -615,6 +618,7 @@ async fn test_fails_to_sign_if_non_signing_group_participants_are_used() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down Expand Up @@ -727,6 +731,7 @@ async fn test_program_with_config() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down Expand Up @@ -936,6 +941,7 @@ async fn test_compute_hash() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down Expand Up @@ -1028,6 +1034,7 @@ async fn test_fail_infinite_program() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down Expand Up @@ -1116,6 +1123,7 @@ async fn test_device_key_proxy() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down Expand Up @@ -1270,6 +1278,7 @@ async fn test_faucet() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down Expand Up @@ -1434,6 +1443,7 @@ async fn test_new_registration_flow() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions crates/threshold-signature-server/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ async fn test_reshare() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async fn integration_test_register_and_sign() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions crates/threshold-signature-server/tests/sign_eth_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async fn integration_test_sign_eth_tx() {
vec![],
vec![],
vec![],
0u8,
)
.await
.unwrap();
Expand Down
5 changes: 3 additions & 2 deletions pallets/registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ benchmarks! {
oracle_data_pointer,
deployer: program_modification_account.clone(),
ref_counter: 0,
version_number: 0,
},
);

Expand Down Expand Up @@ -249,8 +250,8 @@ benchmarks! {
}; n as usize])
.unwrap();
let sig_req_account: T::AccountId = whitelisted_caller();
Programs::<T>::insert(program_hash, ProgramInfo {bytecode: program, configuration_schema: configuration_schema.clone(), auxiliary_data_schema: auxiliary_data_schema.clone(), oracle_data_pointer: oracle_data_pointer.clone(), deployer: program_modification_account.clone(), ref_counter: 0});
Programs::<T>::insert(new_program_hash, ProgramInfo {bytecode: new_program, configuration_schema, auxiliary_data_schema, oracle_data_pointer, deployer: program_modification_account.clone(), ref_counter: o as u128});
Programs::<T>::insert(program_hash, ProgramInfo {bytecode: program, configuration_schema: configuration_schema.clone(), auxiliary_data_schema: auxiliary_data_schema.clone(), oracle_data_pointer: oracle_data_pointer.clone(), deployer: program_modification_account.clone(), ref_counter: 0, version_number: 0});
Programs::<T>::insert(new_program_hash, ProgramInfo {bytecode: new_program, configuration_schema, auxiliary_data_schema, oracle_data_pointer, deployer: program_modification_account.clone(), ref_counter: o as u128, version_number: 0});
let balance = <T as pallet_staking_extension::Config>::Currency::minimum_balance() * 100u32.into();
let _ = <T as pallet_staking_extension::Config>::Currency::make_free_balance_be(&sig_req_account, balance);
<Registered<T>>::insert(
Expand Down
3 changes: 3 additions & 0 deletions pallets/registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn setup_programs(
oracle_data_pointer: empty_program.clone(),
deployer: alice,
ref_counter: 0,
version_number: 0,
},
);

Expand Down Expand Up @@ -433,6 +434,7 @@ fn it_changes_a_program_instance() {
oracle_data_pointer: empty_program.clone(),
deployer: 1,
ref_counter: 1,
version_number: 0,
},
);

Expand All @@ -453,6 +455,7 @@ fn it_changes_a_program_instance() {
oracle_data_pointer: empty_program.clone(),
deployer: 1,
ref_counter: 1,
version_number: 0,
},
);

Expand Down
1 change: 1 addition & 0 deletions pallets/transaction-pause/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ fn paused_transaction_filter_work() {
configuration_schema: vec![],
auxiliary_data_schema: vec![],
oracle_data_pointer: vec![],
version_number: 0u8,
});
assert!(!PausedTransactionFilter::<Runtime>::contains(BALANCE_TRANSFER));
assert!(!PausedTransactionFilter::<Runtime>::contains(whitelist_address_call));
Expand Down

0 comments on commit d2f37d4

Please sign in to comment.