Rename more things related to contract instantiation (#3664)

* Rename more things related to contract instantiation

* rename `creator_ch`

* Fix node runtime

* fix contracts tests

* Little fix
This commit is contained in:
Ashley
2019-09-23 21:32:44 +12:00
committed by Sergei Pepyakin
parent e0b3564f2d
commit 0a469666c1
8 changed files with 117 additions and 114 deletions
+9 -9
View File
@@ -173,7 +173,7 @@ mod tests {
}
#[derive(Debug, PartialEq, Eq)]
struct CreateEntry {
struct InstantiateEntry {
code_hash: H256,
endowment: u64,
data: Vec<u8>,
@@ -192,7 +192,7 @@ mod tests {
pub struct MockExt {
storage: HashMap<StorageKey, Vec<u8>>,
rent_allowance: u64,
creates: Vec<CreateEntry>,
instantiates: Vec<InstantiateEntry>,
transfers: Vec<TransferEntry>,
dispatches: Vec<DispatchEntry>,
restores: Vec<RestoreEntry>,
@@ -220,7 +220,7 @@ mod tests {
gas_meter: &mut GasMeter<Test>,
data: Vec<u8>,
) -> Result<(u64, ExecReturnValue), ExecError> {
self.creates.push(CreateEntry {
self.instantiates.push(InstantiateEntry {
code_hash: code_hash.clone(),
endowment,
data: data.to_vec(),
@@ -476,7 +476,7 @@ mod tests {
);
}
const CODE_CREATE: &str = r#"
const CODE_INSTANTIATE: &str = r#"
(module
;; ext_instantiate(
;; code_ptr: u32,
@@ -507,7 +507,7 @@ mod tests {
;; Amount of value to transfer.
;; Represented by u64 (8 bytes long) in little endian.
(data (i32.const 4) "\03\00\00\00\00\00\00\00")
;; Input data to pass to the contract being created.
;; Input data to pass to the contract being instantiated.
(data (i32.const 12) "\01\02\03\04")
;; Hash of code.
(data (i32.const 16)
@@ -518,18 +518,18 @@ mod tests {
"#;
#[test]
fn contract_create() {
fn contract_instantiate() {
let mut mock_ext = MockExt::default();
let _ = execute(
CODE_CREATE,
CODE_INSTANTIATE,
vec![],
&mut mock_ext,
&mut GasMeter::with_limit(50_000, 1),
).unwrap();
assert_eq!(
&mock_ext.creates,
&[CreateEntry {
&mock_ext.instantiates,
&[InstantiateEntry {
code_hash: [0x11; 32].into(),
endowment: 3,
data: vec![1, 2, 3, 4],
+14 -12
View File
@@ -432,11 +432,12 @@ define_env!(Env, <E: Ext>,
// by the code hash.
//
// If the constructor runs to completion, then this returns the status code that the newly
// created contract returns on exit in the bottom 8 bits of the return value. The top 24 bits
// are 0s. A status code of 0 indicates success, and any other code indicates a failure. On
// failure, any state changes made by the called contract are reverted and the contract is not
// instantiated. On a success status, the scratch buffer is filled with the encoded address of
// the newly created contract. In the case of a failure status, the scratch buffer is cleared.
// instantiated contract returns on exit in the bottom 8 bits of the return value. The top 24
// bits are 0s. A status code of 0 indicates success, and any other code indicates a failure.
// On failure, any state changes made by the called contract are reverted and the contract is
// not instantiated. On a success status, the scratch buffer is filled with the encoded address
// of the newly instantiated contract. In the case of a failure status, the scratch buffer is
// cleared.
//
// If the contract traps during execution or otherwise fails to complete successfully, then
// this function clears the scratch buffer and returns 0x0100. As with a failure status, any
@@ -445,8 +446,9 @@ define_env!(Env, <E: Ext>,
// This function creates an account and executes initializer code. After the execution,
// the returned buffer is saved as the code of the created account.
//
// Returns 0 on the successful contract creation and puts the address of the created contract
// into the scratch buffer. Otherwise, returns non-zero value and clears the scratch buffer.
// Returns 0 on the successful contract instantiation and puts the address of the instantiated
// contract into the scratch buffer. Otherwise, returns non-zero value and clears the scratch
// buffer.
//
// - code_hash_ptr: a pointer to the buffer that contains the initializer code.
// - code_hash_len: length of the initializer code buffer.
@@ -535,9 +537,9 @@ define_env!(Env, <E: Ext>,
// Stores the address of the caller into the scratch buffer.
//
// If this is a top-level call (i.e. initiated by an extrinsic) the origin address of the extrinsic
// will be returned. Otherwise, if this call is initiated by another contract then the address
// of the contract will be returned.
// If this is a top-level call (i.e. initiated by an extrinsic) the origin address of the
// extrinsic will be returned. Otherwise, if this call is initiated by another contract then the
// address of the contract will be returned.
ext_caller(ctx) => {
ctx.scratch_buf.clear();
ctx.ext.caller().encode_to(&mut ctx.scratch_buf);
@@ -717,8 +719,8 @@ define_env!(Env, <E: Ext>,
Ok(ctx.scratch_buf.len() as u32)
},
// Copy data from the scratch buffer starting from `offset` with length `len` into the contract memory.
// The region at which the data should be put is specified by `dest_ptr`.
// Copy data from the scratch buffer starting from `offset` with length `len` into the contract
// memory. The region at which the data should be put is specified by `dest_ptr`.
//
// In order to get size of the scratch buffer use `ext_scratch_size`. At the start of contract
// execution, the scratch buffer is filled with the input data. Whenever a contract calls