Skip to content

Commit 2477741

Browse files
committed
update creating account functions
1 parent 6e74f45 commit 2477741

File tree

4 files changed

+32
-45
lines changed

4 files changed

+32
-45
lines changed

executor/benchmark/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ use starcoin_storage::storage::StorageInstance;
1616
use starcoin_storage::Storage;
1717
use starcoin_transaction_builder::{
1818
create_signed_txn_with_association_account, encode_create_account_script_function,
19-
encode_transfer_script_function,
19+
encode_transfer_script_by_token_code, encode_transfer_script_function,
2020
};
2121
use starcoin_types::{
2222
account_address,
2323
account_address::AccountAddress,
2424
block_metadata::BlockMetadata,
2525
transaction::{Transaction, TransactionPayload},
2626
};
27+
use starcoin_vm_types::account_config::G_STC_TOKEN_CODE;
2728
use starcoin_vm_types::genesis_config::StdlibVersion;
2829
use starcoin_vm_types::token::stc;
2930
use starcoin_vm_types::transaction::authenticator::AuthenticationKey;
@@ -127,13 +128,11 @@ impl TransactionGenerator {
127128
for (j, account) in block.iter().enumerate() {
128129
let txn = create_transaction(
129130
self.sequence,
130-
TransactionPayload::EntryFunction(encode_create_account_script_function(
131-
StdlibVersion::Latest,
132-
stc::stc_type_tag(),
133-
&account.address,
134-
AuthenticationKey::ed25519(account.public_key()),
131+
encode_transfer_script_by_token_code(
132+
account.address,
135133
init_account_balance as u128,
136-
)),
134+
G_STC_TOKEN_CODE.clone(),
135+
),
137136
self.net.time_service().now_secs() + j as u64 + 1,
138137
&self.net,
139138
);

executor/tests/executor_test.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ use test_helper::executor::{
3333
TEST_MODULE, TEST_MODULE_1, TEST_MODULE_2,
3434
};
3535

36-
use test_helper::executor::{
37-
compile_modules_with_address, execute_and_apply, get_balance, get_sequence_number,
38-
prepare_genesis,
39-
};
4036
// use test_helper::Account;
4137
use starcoin_state_api::StateReaderExt;
4238
use starcoin_types::account::Account;
@@ -45,6 +41,10 @@ use starcoin_vm_runtime::starcoin_vm::{chunk_block_transactions, StarcoinVM};
4541
use starcoin_vm_types::account_config::core_code_address;
4642
use starcoin_vm_types::state_store::state_key::StateKey;
4743
use starcoin_vm_types::state_store::state_value::StateValue;
44+
use test_helper::executor::{
45+
compile_modules_with_address, execute_and_apply, get_balance, get_sequence_number,
46+
prepare_genesis,
47+
};
4848
use test_helper::txn::create_account_txn_sent_as_association;
4949

5050
#[derive(Default)]
@@ -201,17 +201,12 @@ fn test_txn_verify_err_case() -> Result<()> {
201201
let mut vm = StarcoinVM::new(None, &chain_state);
202202
let alice = Account::new();
203203
let bob = Account::new();
204-
let script_function = encode_create_account_script_function(
205-
net.stdlib_version(),
206-
stc_type_tag(),
207-
alice.address(),
208-
alice.auth_key(),
209-
100000,
210-
);
204+
let script_function =
205+
encode_transfer_script_by_token_code(*alice.address(), 100000, G_STC_TOKEN_CODE.clone());
211206
let txn = RawUserTransaction::new_with_default_gas_token(
212207
*alice.address(),
213208
0,
214-
TransactionPayload::EntryFunction(script_function),
209+
script_function,
215210
10000000,
216211
1,
217212
1000 + 60 * 60,

test-helper/src/dao.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ use starcoin_executor::execute_readonly_function;
1919
use starcoin_logger::prelude::*;
2020
use starcoin_state_api::ChainStateReader;
2121
use starcoin_statedb::ChainStateDB;
22-
use starcoin_transaction_builder::encode_create_account_script_function;
22+
use starcoin_transaction_builder::encode_transfer_script_by_token_code;
2323
use starcoin_types::account_address::AccountAddress;
2424
use starcoin_types::account_config::{association_address, genesis_address, stc_type_tag};
2525
use starcoin_types::block_metadata::BlockMetadata;
2626
use starcoin_types::identifier::Identifier;
2727
use starcoin_types::language_storage::{ModuleId, StructTag, TypeTag};
2828
use starcoin_types::transaction::{EntryFunction, TransactionPayload};
29-
use starcoin_vm_types::account_config::core_code_address;
29+
use starcoin_vm_types::account_config::{core_code_address, G_STC_TOKEN_CODE};
3030
use starcoin_vm_types::on_chain_config::VMConfig;
3131
use starcoin_vm_types::value::{serialize_values, MoveValue};
3232
use starcoin_vm_types::StateView;
@@ -50,7 +50,7 @@ pub fn proposal_state<S: StateView>(
5050
) -> u8 {
5151
let mut ret = execute_readonly_function(
5252
state_view,
53-
&ModuleId::new(genesis_address(), Identifier::new("Dao").unwrap()),
53+
&ModuleId::new(genesis_address(), Identifier::new("dao").unwrap()),
5454
&Identifier::new("proposal_state").unwrap(),
5555
vec![token, action_ty.clone()],
5656
serialize_values(&vec![
@@ -78,7 +78,7 @@ pub fn proposal_exist<S: StateView>(
7878
) -> bool {
7979
let mut ret = execute_readonly_function(
8080
state_view,
81-
&ModuleId::new(genesis_address(), Identifier::new("Dao").unwrap()),
81+
&ModuleId::new(genesis_address(), Identifier::new("dao").unwrap()),
8282
&Identifier::new("proposal_exists").unwrap(),
8383
vec![token, action_ty],
8484
serialize_values(&vec![
@@ -95,7 +95,7 @@ pub fn proposal_exist<S: StateView>(
9595
pub fn on_chain_config_type_tag(params_type_tag: TypeTag) -> TypeTag {
9696
TypeTag::Struct(Box::new(StructTag {
9797
address: genesis_address(),
98-
module: Identifier::new("OnChainConfigDao").unwrap(),
98+
module: Identifier::new("on_chain_config_dao").unwrap(),
9999
name: Identifier::new("OnChainConfigUpdate").unwrap(),
100100
type_args: vec![params_type_tag],
101101
}))
@@ -104,7 +104,7 @@ pub fn on_chain_config_type_tag(params_type_tag: TypeTag) -> TypeTag {
104104
pub fn reward_config_type_tag() -> TypeTag {
105105
TypeTag::Struct(Box::new(StructTag {
106106
address: genesis_address(),
107-
module: Identifier::new("RewardConfig").unwrap(),
107+
module: Identifier::new("block_reward_config").unwrap(),
108108
name: Identifier::new("RewardConfig").unwrap(),
109109
type_args: vec![],
110110
}))
@@ -113,7 +113,7 @@ pub fn reward_config_type_tag() -> TypeTag {
113113
pub fn transaction_timeout_type_tag() -> TypeTag {
114114
TypeTag::Struct(Box::new(StructTag {
115115
address: genesis_address(),
116-
module: Identifier::new("TransactionTimeoutConfig").unwrap(),
116+
module: Identifier::new("stc_transaction_timeout_config").unwrap(),
117117
name: Identifier::new("TransactionTimeoutConfig").unwrap(),
118118
type_args: vec![],
119119
}))
@@ -122,7 +122,7 @@ pub fn transaction_timeout_type_tag() -> TypeTag {
122122
pub fn txn_publish_config_type_tag() -> TypeTag {
123123
TypeTag::Struct(Box::new(StructTag {
124124
address: genesis_address(),
125-
module: Identifier::new("TransactionPublishOption").unwrap(),
125+
module: Identifier::new("transaction_publish_option").unwrap(),
126126
name: Identifier::new("TransactionPublishOption").unwrap(),
127127
type_args: vec![],
128128
}))
@@ -151,23 +151,18 @@ pub fn execute_create_account(
151151
)?;
152152
if !chain_state.exist_account(alice.address())? {
153153
let init_balance = pre_mint_amount / 4;
154-
let script_function = encode_create_account_script_function(
155-
net.stdlib_version(),
156-
stc_type_tag(),
157-
alice.address(),
158-
alice.auth_key(),
154+
let script_function = encode_transfer_script_by_token_code(
155+
*alice.address(),
159156
init_balance,
157+
G_STC_TOKEN_CODE.clone(),
160158
);
159+
161160
debug!(
162161
"execute create account script: addr:{}, init_balance:{}",
163162
alice.address(),
164163
init_balance
165164
);
166-
association_execute_should_success(
167-
net,
168-
chain_state,
169-
TransactionPayload::EntryFunction(script_function),
170-
)?;
165+
association_execute_should_success(net, chain_state, script_function)?;
171166
}
172167

173168
Ok(())

test-helper/src/txn.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use crate::Account;
55
use starcoin_config::ChainNetwork;
66
use starcoin_transaction_builder::{
7-
create_signed_txn_with_association_account, encode_create_account_script_function,
8-
encode_transfer_script_by_token_code, DEFAULT_MAX_GAS_AMOUNT,
7+
create_signed_txn_with_association_account, encode_transfer_script_by_token_code,
8+
DEFAULT_MAX_GAS_AMOUNT,
99
};
1010
use starcoin_txpool::TxPoolService;
1111
use starcoin_txpool_api::TxPoolSyncService;
@@ -156,19 +156,17 @@ pub fn create_user_txn(
156156
pre_mint_amount: u128,
157157
expire_time: u64,
158158
) -> anyhow::Result<Vec<SignedUserTransaction>> {
159-
let script_function = encode_create_account_script_function(
160-
net.stdlib_version(),
161-
stc_type_tag(),
162-
alice.address(),
163-
alice.auth_key(),
159+
let script_function = encode_transfer_script_by_token_code(
160+
*alice.address(),
164161
pre_mint_amount / 4,
162+
G_STC_TOKEN_CODE.clone(),
165163
);
166164
let txn = net
167165
.genesis_config()
168166
.sign_with_association(build_transaction(
169167
address,
170168
seq_number,
171-
TransactionPayload::EntryFunction(script_function),
169+
script_function,
172170
expire_time + 60 * 60,
173171
))?;
174172
Ok(vec![txn])

0 commit comments

Comments
 (0)