Skip to content

Commit

Permalink
Fix tests and clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi committed Dec 28, 2024
1 parent 01f83e1 commit 819ed2e
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 41 deletions.
10 changes: 5 additions & 5 deletions crates/env/src/call/create_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ where
/// # }
/// # use contract::MyContractRef;
/// let my_contract: MyContractRef = build_create::<MyContractRef>()
/// .code_hash(Hash::from([0x42; 32]))
/// .endowment(25)
/// .code_hash(ink::H256::from([0x42; 32]))
/// .endowment(25.into())
/// .exec_input(
/// ExecutionInput::new(Selector::new(ink::selector_bytes!("my_constructor")))
/// .push_arg(42)
Expand Down Expand Up @@ -412,8 +412,8 @@ where
/// # }
/// # use contract::{MyContractRef, ConstructorError};
/// let my_contract: MyContractRef = build_create::<MyContractRef>()
/// .code_hash(Hash::from([0x42; 32]))
/// .endowment(25)
/// .code_hash(ink::H256::from([0x42; 32]))
/// .endowment(25.into())
/// .exec_input(
/// ExecutionInput::new(Selector::new(ink::selector_bytes!("my_constructor")))
/// .push_arg(42)
Expand Down Expand Up @@ -531,7 +531,7 @@ where
CreateBuilder {
code_hash: self.code_hash,
limits: self.limits,
endowment: endowment,
endowment,
exec_input: self.exec_input,
salt: self.salt,
return_type: self.return_type,
Expand Down
1 change: 1 addition & 0 deletions crates/env/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
/// type BlockNumber = u32;
/// type Timestamp = u64;
/// type ChainExtension = <DefaultEnvironment as Environment>::ChainExtension;
/// type EventRecord = <DefaultEnvironment as Environment>::EventRecord;
/// }
///
/// #[ink::contract(env = super::CustomEnvironment)]
Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/engine/on_chain/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a> EncodeScope<'a> {
}
}

impl<'a> scale::Output for EncodeScope<'a> {
impl scale::Output for EncodeScope<'_> {
fn write(&mut self, bytes: &[u8]) {
debug_assert!(
self.len().checked_add(bytes.len()).unwrap() <= self.capacity(),
Expand Down
8 changes: 5 additions & 3 deletions crates/env/src/engine/on_chain/pallet_revive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,11 @@ impl TypedEnvBackend for EnvInstance {
Some(output),
);
match call_result {
Ok(()) | Err(ReturnErrorCode::CalleeReverted) => {
let decoded = scale::DecodeAll::decode_all(&mut &output[..])?;
Ok(decoded)
Ok(()) => {
// no need to decode, is ()
//let decoded = scale::DecodeAll::decode_all(&mut &output[..])?;
//Ok(decoded)
Ok(())
}
Err(actual_error) => Err(actual_error.into()),
}
Expand Down
40 changes: 22 additions & 18 deletions crates/ink/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream {
/// type Timestamp = u64;
/// type BlockNumber = u32;
/// type ChainExtension = ::ink::env::NoChainExtension;
/// type EventRecord = ();
/// }
/// ```
/// A user might implement their ink! smart contract using the above custom
Expand All @@ -189,6 +190,7 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream {
/// # type Timestamp = u64;
/// # type BlockNumber = u32;
/// # type ChainExtension = ::ink::env::NoChainExtension;
/// # type EventRecord = ();
/// # }
/// #
/// # #[ink(storage)]
Expand Down Expand Up @@ -398,7 +400,7 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream {
/// For example it is possible to query the current call's caller via:
/// ```
/// # ink_env::test::run_test::<ink_env::DefaultEnvironment, _>(|_| {
/// let caller = ink_env::caller::<ink_env::DefaultEnvironment>();
/// let caller = ink_env::caller();
/// # let _caller = caller;
/// # Ok(())
/// # }).unwrap();
Expand Down Expand Up @@ -445,23 +447,25 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream {
/// ```
/// #[ink::contract]
/// mod erc20 {
/// use ink::{H160, U256};
///
/// /// Defines an event that is emitted every time value is transferred.
/// #[ink(event)]
/// pub struct Transferred {
/// from: Option<AccountId>,
/// to: Option<AccountId>,
/// value: Balance,
/// from: Option<H160>,
/// to: Option<H160>,
/// value: U256,
/// }
///
/// #[ink(storage)]
/// pub struct Erc20 {
/// total_supply: Balance,
/// total_supply: U256,
/// // more fields...
/// }
///
/// impl Erc20 {
/// #[ink(constructor)]
/// pub fn new(initial_supply: Balance) -> Self {
/// pub fn new(initial_supply: U256) -> Self {
/// let caller = Self::env().caller();
/// Self::env().emit_event(Transferred {
/// from: None,
Expand All @@ -474,7 +478,7 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream {
/// }
///
/// #[ink(message)]
/// pub fn total_supply(&self) -> Balance {
/// pub fn total_supply(&self) -> U256 {
/// self.total_supply
/// }
/// }
Expand Down Expand Up @@ -538,18 +542,15 @@ pub fn contract(attr: TokenStream, item: TokenStream) -> TokenStream {
/// # Trait definition:
///
/// ```
/// # type Balance = <ink_env::DefaultEnvironment as ink_env::Environment>::Balance;
/// # type AccountId = <ink_env::DefaultEnvironment as ink_env::Environment>::AccountId;
///
/// #[ink::trait_definition]
/// pub trait Erc20 {
/// /// Returns the total supply of the ERC-20 smart contract.
/// #[ink(message)]
/// fn total_supply(&self) -> Balance;
/// fn total_supply(&self) -> ink::U256;
///
/// /// Transfers balance from the caller to the given address.
/// #[ink(message)]
/// fn transfer(&mut self, amount: Balance, to: ink::H160) -> bool;
/// fn transfer(&mut self, amount: ink::U256, to: ink::H160) -> bool;
///
/// // etc.
/// }
Expand All @@ -562,39 +563,40 @@ pub fn contract(attr: TokenStream, item: TokenStream) -> TokenStream {
/// ```
/// #[ink::contract]
/// mod base_erc20 {
/// use ink::{H160, U256};
/// # // We somehow cannot put the trait in the doc-test crate root due to bugs.
/// # #[ink::trait_definition]
/// # pub trait Erc20 {
/// # /// Returns the total supply of the ERC-20 smart contract.
/// # #[ink(message)]
/// # fn total_supply(&self) -> Balance;
/// # fn total_supply(&self) -> U256;
/// #
/// # /// Transfers balance from the caller to the given address.
/// # #[ink(message)]
/// # fn transfer(&mut self, amount: Balance, to: H160) -> bool;
/// # fn transfer(&mut self, amount: U256, to: H160) -> bool;
/// # }
/// #
/// #[ink(storage)]
/// pub struct BaseErc20 {
/// total_supply: Balance,
/// total_supply: U256,
/// }
///
/// impl BaseErc20 {
/// #[ink(constructor)]
/// pub fn new(initial_supply: Balance) -> Self {
/// pub fn new(initial_supply: U256) -> Self {
/// Self { total_supply: initial_supply }
/// }
/// }
///
/// impl Erc20 for BaseErc20 {
/// /// Returns the total supply of the ERC-20 smart contract.
/// #[ink(message)]
/// fn total_supply(&self) -> Balance {
/// fn total_supply(&self) -> H256 {
/// self.total_supply
/// }
///
/// #[ink(message)]
/// fn transfer(&mut self, amount: Balance, to: H160) -> bool {
/// fn transfer(&mut self, amount: U256, to: H160) -> bool {
/// unimplemented!()
/// }
/// }
Expand Down Expand Up @@ -1180,6 +1182,7 @@ pub fn test(attr: TokenStream, item: TokenStream) -> TokenStream {
/// type Hash = <DefaultEnvironment as Environment>::Hash;
/// type BlockNumber = <DefaultEnvironment as Environment>::BlockNumber;
/// type Timestamp = <DefaultEnvironment as Environment>::Timestamp;
/// type EventRecord = <DefaultEnvironment as Environment>::EventRecord;
///
/// type ChainExtension = RuntimeReadWrite;
/// }
Expand Down Expand Up @@ -1321,6 +1324,7 @@ pub fn test(attr: TokenStream, item: TokenStream) -> TokenStream {
/// # type Hash = <ink_env::DefaultEnvironment as ink_env::Environment>::Hash;
/// # type BlockNumber = <ink_env::DefaultEnvironment as ink_env::Environment>::BlockNumber;
/// # type Timestamp = <ink_env::DefaultEnvironment as ink_env::Environment>::Timestamp;
/// # type EventRecord = <ink_env::DefaultEnvironment as ink_env::Environment>::EventRecord;
/// #
/// # type ChainExtension = RuntimeReadWrite;
/// # }
Expand Down
8 changes: 4 additions & 4 deletions crates/ink/src/env_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ where
/// #
/// /// Returns the contract's balance.
/// #[ink(message)]
/// pub fn my_balance(&self) -> Balance {
/// pub fn my_balance(&self) -> ink::U256 {
/// self.env().balance()
/// }
/// #
Expand Down Expand Up @@ -440,14 +440,14 @@ where
/// .ref_time_limit(500_000_000)
/// .proof_size_limit(100_000)
/// .storage_deposit_limit(500_000_000_000)
/// .endowment(25)
/// .endowment(25.into())
/// .exec_input(
/// ExecutionInput::new(Selector::new(ink::selector_bytes!("new")))
/// .push_arg(42)
/// .push_arg(true)
/// .push_arg(&[0x10u8; 32]),
/// )
/// .salt_bytes(Some([0xCA, 0xFE, 0xBA, 0xBE]))
/// .salt_bytes(Some([0x13; 32]))
/// .returns::<OtherContractRef>()
/// .params();
/// self.env()
Expand Down Expand Up @@ -590,7 +590,7 @@ where
/// pub fn invoke_contract_delegate(&self) -> i32 {
/// let call_params = build_call::<DefaultEnvironment>()
/// .call_type(DelegateCall::new(
/// ink::H256::zero(),
/// ink::H160::zero(),
/// ))
/// .exec_input(
/// ExecutionInput::new(Selector::new([0xCA, 0xFE, 0xBA, 0xBE]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ error[E0277]: the trait bound `Result<u8, contract::Error>: ConstructorReturnTyp
= help: the following other types implement trait `ConstructorReturnType<C>`:
`Result<C, E>` implements `ConstructorReturnType<C>`
`Result<Contract, E>` implements `ConstructorReturnType<ContractRef>`
note: required by a bound in `CreateBuilder::<E, ContractRef, Limits, Endowment, Args, Salt, Unset<ReturnType<()>>>::returns`
note: required by a bound in `CreateBuilder::<E, ContractRef, Limits, Args, Unset<ReturnType<()>>>::returns`
--> $WORKSPACE/crates/env/src/call/create_builder.rs
|
| pub fn returns<R>(
| ------- required by a bound in this associated function
...
| R: ConstructorReturnType<ContractRef>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `CreateBuilder::<E, ContractRef, Limits, Endowment, Args, Salt, Unset<ReturnType<()>>>::returns`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `CreateBuilder::<E, ContractRef, Limits, Args, Unset<ReturnType<()>>>::returns`

error[E0277]: the trait bound `ConstructorOutputValue<Result<u8, contract::Error>>: ConstructorOutput<Contract>` is not satisfied
--> tests/ui/contract/fail/constructor-return-result-invalid.rs:4:16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ error[E0277]: the trait bound `contract::Error: WrapperTypeDecode` is not satisf
sp_core::Bytes
= note: required for `contract::Error` to implement `ink::parity_scale_codec::Decode`
= note: required for `Result<ContractRef, contract::Error>` to implement `ConstructorReturnType<ContractRef>`
note: required by a bound in `CreateBuilder::<E, ContractRef, Limits, Endowment, Args, Salt, Unset<ReturnType<()>>>::returns`
note: required by a bound in `CreateBuilder::<E, ContractRef, Limits, Args, Unset<ReturnType<()>>>::returns`
--> $WORKSPACE/crates/env/src/call/create_builder.rs
|
| pub fn returns<R>(
| ------- required by a bound in this associated function
...
| R: ConstructorReturnType<ContractRef>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `CreateBuilder::<E, ContractRef, Limits, Endowment, Args, Salt, Unset<ReturnType<()>>>::returns`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `CreateBuilder::<E, ContractRef, Limits, Args, Unset<ReturnType<()>>>::returns`

error[E0277]: the trait bound `contract::Error: TypeInfo` is not satisfied
--> tests/ui/contract/fail/constructor-return-result-non-codec-error.rs:4:16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() {
let _: fn() -> CalleeRef = || {
CalleeRef::new_self()
.code_hash(ink::primitives::H256::zero())
.endowment(25)
.endowment(ink::U256::from(25))
.salt_bytes(Some([1u8; 32]))
.instantiate()
};
Expand All @@ -54,7 +54,7 @@ fn main() {
let _: fn() -> CalleeRef = || {
CalleeRef::new_storage_name()
.code_hash(ink::primitives::H256::zero())
.endowment(25)
.endowment(ink::U256::from(25))
.salt_bytes(Some([1u8; 32]))
.instantiate()
};
Expand All @@ -63,7 +63,7 @@ fn main() {
let _: fn() -> Result<CalleeRef, Error> = || {
CalleeRef::new_result_self()
.code_hash(ink::primitives::H256::zero())
.endowment(25)
.endowment(ink::U256::from(25))
.salt_bytes(Some([1u8; 32]))
.instantiate()
};
Expand All @@ -72,7 +72,7 @@ fn main() {
let _: fn() -> Result<CalleeRef, Error> = || {
CalleeRef::new_result_self()
.code_hash(ink::primitives::H256::zero())
.endowment(25)
.endowment(ink::U256::from(25))
.salt_bytes(Some([1u8; 32]))
.instantiate()
};
Expand Down
1 change: 1 addition & 0 deletions integration-tests/public/combined-extension/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl Environment for CustomEnvironment {
type Hash = <DefaultEnvironment as Environment>::Hash;
type Timestamp = <DefaultEnvironment as Environment>::Timestamp;
type BlockNumber = <DefaultEnvironment as Environment>::BlockNumber;
type EventRecord = <DefaultEnvironment as Environment>::EventRecord;

/// Setting up the combined chain extension as a primary extension.
///
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/public/multi-contract-caller/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ mod multi_contract_caller {
.code_hash;

let mut constructor = MultiContractCallerRef::new(
123, // initial value
1234, // initial value
1337, // salt
accumulator_hash,
adder_hash,
Expand Down
1 change: 1 addition & 0 deletions integration-tests/public/psp22-extension/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl Environment for CustomEnvironment {
type Hash = <ink::env::DefaultEnvironment as Environment>::Hash;
type Timestamp = <ink::env::DefaultEnvironment as Environment>::Timestamp;
type BlockNumber = <ink::env::DefaultEnvironment as Environment>::BlockNumber;
type EventRecord = <DefaultEnvironment as Environment>::EventRecord;

type ChainExtension = crate::Psp22Extension;
}
Expand Down
1 change: 1 addition & 0 deletions integration-tests/public/rand-extension/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl Environment for CustomEnvironment {
type Hash = <ink::env::DefaultEnvironment as Environment>::Hash;
type BlockNumber = <ink::env::DefaultEnvironment as Environment>::BlockNumber;
type Timestamp = <ink::env::DefaultEnvironment as Environment>::Timestamp;
type EventRecord = <DefaultEnvironment as Environment>::EventRecord;

type ChainExtension = FetchRandom;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod delegator {
pub struct Delegator {
addresses: Mapping<H160, i32, ManualKey<0x23>>,
counter: i32,
delegate_to: Lazy<H256>,
delegate_to: Lazy<H160>,
}

impl Delegator {
Expand Down

0 comments on commit 819ed2e

Please sign in to comment.