Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #7110 from paritytech/remove-storage-error
Browse files Browse the repository at this point in the history
WASM storage_read and storage_write don't return anything
  • Loading branch information
debris authored and tomusdrw committed Dec 4, 2017
1 parent aeb43b6 commit a8cf4ef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ethcore/res/wasm-tests
4 changes: 2 additions & 2 deletions ethcore/wasm/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ pub const SIGNATURES: &'static [UserFunctionDescriptor] = &[
Static(
"_storage_read",
&[I32; 2],
Some(I32),
None,
),
Static(
"_storage_write",
&[I32; 2],
Some(I32),
None,
),
Static(
"_balance",
Expand Down
4 changes: 2 additions & 2 deletions ethcore/wasm/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'a, 'b> Runtime<'a, 'b> {

self.ext.set_storage(key, val).map_err(|_| UserTrap::StorageUpdateError)?;

Ok(Some(0i32.into()))
Ok(None)
}

/// Read from the storage to wasm memory
Expand All @@ -184,7 +184,7 @@ impl<'a, 'b> Runtime<'a, 'b> {

self.memory.set(val_ptr as u32, &*val)?;

Ok(Some(0.into()))
Ok(None)
}

/// Fetches balance for address
Expand Down
38 changes: 19 additions & 19 deletions ethcore/wasm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn logger() {
U256::from(1_000_000_000),
"Logger sets 0x04 key to the trasferred value"
);
assert_eq!(gas_left, U256::from(19_143));
assert_eq!(gas_left, U256::from(19_147));
}

// This test checks if the contract can allocate memory and pass pointer to the result stream properly.
Expand Down Expand Up @@ -180,7 +180,7 @@ fn dispersion() {
result,
vec![0u8, 0, 125, 11, 197, 7, 255, 8, 19, 0]
);
assert_eq!(gas_left, U256::from(96_961));
assert_eq!(gas_left, U256::from(96_393));
}

#[test]
Expand Down Expand Up @@ -208,7 +208,7 @@ fn suicide_not() {
result,
vec![0u8]
);
assert_eq!(gas_left, U256::from(97_290));
assert_eq!(gas_left, U256::from(96_725));
}

#[test]
Expand Down Expand Up @@ -240,7 +240,7 @@ fn suicide() {
};

assert!(ext.suicides.contains(&refund));
assert_eq!(gas_left, U256::from(97_249));
assert_eq!(gas_left, U256::from(96_687));
}

#[test]
Expand Down Expand Up @@ -270,15 +270,15 @@ fn create() {
assert!(ext.calls.contains(
&FakeCall {
call_type: FakeCallType::Create,
gas: U256::from(65_903),
gas: U256::from(65_899),
sender_address: None,
receive_address: None,
value: Some(1_000_000_000.into()),
data: vec![0u8, 2, 4, 8, 16, 32, 64, 128],
code_address: None,
}
));
assert_eq!(gas_left, U256::from(65_896));
assert_eq!(gas_left, U256::from(65_892));
}


Expand Down Expand Up @@ -393,7 +393,7 @@ fn realloc() {
}
};
assert_eq!(result, vec![0u8; 2]);
assert_eq!(gas_left, U256::from(97_278));
assert_eq!(gas_left, U256::from(96_723));
}

// Tests that contract's ability to read from a storage
Expand All @@ -419,7 +419,7 @@ fn storage_read() {
};

assert_eq!(Address::from(&result[12..32]), address);
assert_eq!(gas_left, U256::from(99_706));
assert_eq!(gas_left, U256::from(99_767));
}

// Tests keccak calculation
Expand All @@ -445,7 +445,7 @@ fn keccak() {
};

assert_eq!(H256::from_slice(&result), H256::from("68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87"));
assert_eq!(gas_left, U256::from(82_009));
assert_eq!(gas_left, U256::from(81_446));
}

// memcpy test.
Expand Down Expand Up @@ -477,7 +477,7 @@ fn memcpy() {
};

assert_eq!(result, test_payload);
assert_eq!(gas_left, U256::from(72_773));
assert_eq!(gas_left, U256::from(72_216));
}

// memmove test.
Expand Down Expand Up @@ -509,7 +509,7 @@ fn memmove() {
};

assert_eq!(result, test_payload);
assert_eq!(gas_left, U256::from(72_773));
assert_eq!(gas_left, U256::from(72_216));
}

// memset test
Expand All @@ -534,7 +534,7 @@ fn memset() {
};

assert_eq!(result, vec![228u8; 8192]);
assert_eq!(gas_left, U256::from(72_763));
assert_eq!(gas_left, U256::from(72_196));
}

macro_rules! reqrep_test {
Expand Down Expand Up @@ -591,7 +591,7 @@ fn math_add() {
U256::from_dec_str("1888888888888888888888888888887").unwrap(),
(&result[..]).into()
);
assert_eq!(gas_left, U256::from(96_084));
assert_eq!(gas_left, U256::from(95_524));
}

// multiplication
Expand All @@ -613,7 +613,7 @@ fn math_mul() {
U256::from_dec_str("888888888888888888888888888887111111111111111111111111111112").unwrap(),
(&result[..]).into()
);
assert_eq!(gas_left, U256::from(95_234));
assert_eq!(gas_left, U256::from(94_674));
}

// subtraction
Expand All @@ -635,7 +635,7 @@ fn math_sub() {
U256::from_dec_str("111111111111111111111111111111").unwrap(),
(&result[..]).into()
);
assert_eq!(gas_left, U256::from(96_076));
assert_eq!(gas_left, U256::from(95_516));
}

// subtraction with overflow
Expand Down Expand Up @@ -677,7 +677,7 @@ fn math_div() {
U256::from_dec_str("1125000").unwrap(),
(&result[..]).into()
);
assert_eq!(gas_left, U256::from(89_074));
assert_eq!(gas_left, U256::from(88_514));
}

// This test checks the ability of wasm contract to invoke
Expand Down Expand Up @@ -765,7 +765,7 @@ fn externs() {
"Gas limit requested and returned does not match"
);

assert_eq!(gas_left, U256::from(95_291));
assert_eq!(gas_left, U256::from(94_733));
}

#[test]
Expand All @@ -791,7 +791,7 @@ fn embedded_keccak() {
};

assert_eq!(H256::from_slice(&result), H256::from("68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87"));
assert_eq!(gas_left, U256::from(82_009));
assert_eq!(gas_left, U256::from(81_446));
}

/// This test checks the correctness of log extern
Expand Down Expand Up @@ -826,5 +826,5 @@ fn events() {
assert_eq!(&log_entry.data, b"gnihtemos");

assert_eq!(&result, b"gnihtemos");
assert_eq!(gas_left, U256::from(80_199));
assert_eq!(gas_left, U256::from(79_637));
}

0 comments on commit a8cf4ef

Please sign in to comment.