Skip to content

Commit 4e93b94

Browse files
authored
Move sandbox to drink_sandbox (#119)
1 parent 25e416f commit 4e93b94

File tree

43 files changed

+3114
-4301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3114
-4301
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.15.0]
9+
10+
- Migrate `Sandbox` related code to `ink_sandbox` crate.
11+
812
## [Unreleased]
913

1014
## [0.14.0]

Cargo.lock

Lines changed: 26 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ homepage = "https://github.com/Cardinal-Cryptography/drink"
1818
license = "Apache-2.0"
1919
readme = "README.md"
2020
repository = "https://github.com/Cardinal-Cryptography/drink"
21-
version = "0.14.0"
21+
version = "0.15.0"
2222

2323
[workspace.dependencies]
2424
anyhow = { version = "1.0.71" }
@@ -41,22 +41,15 @@ serde_json = { version = "1.0" }
4141
syn = { version = "2" }
4242
thiserror = { version = "1.0.40" }
4343
wat = { version = "1.0.71" }
44+
ink_sandbox = { version = "5.0.0" }
4445

4546
# Substrate dependencies
4647

47-
frame-metadata = { version = "16.0.0" }
4848
frame-support = { version = "30.0.0"}
4949
frame-system = { version = "30.0.0" }
50-
pallet-balances = { version = "30.0.0" }
51-
pallet-contracts = { version = "29.0.0" }
52-
pallet-contracts-uapi = { package = "pallet-contracts-uapi-next", version = "=6.0.3", default-features = false }
53-
pallet-timestamp = { version = "29.0.0"}
54-
sp-core = { version = "30.0.0" }
55-
sp-externalities = { version = "0.27.0" }
56-
sp-io = { version = "32.0.0" }
5750
sp-runtime-interface = { version = "26.0.0" }
5851

5952
# Local dependencies
6053

61-
drink = { version = "=0.14.0", path = "drink" }
62-
drink-test-macro = { version = "=0.14.0", path = "drink/test-macro" }
54+
drink = { version = "=0.15.0", path = "drink" }
55+
drink-test-macro = { version = "=0.15.0", path = "drink/test-macro" }

drink-cli/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,5 @@ contract-transcode = { workspace = true }
1818
ratatui = { workspace = true, features = ["all-widgets"] }
1919
thiserror = { workspace = true }
2020

21-
pallet-contracts = { workspace = true }
22-
sp-core = { workspace = true, features = ["serde"] }
23-
21+
ink_sandbox = { workspace = true }
2422
drink = { workspace = true, features = ["session"] }

drink-cli/src/app_state/contracts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{path::PathBuf, rc::Rc};
22

33
use contract_transcode::ContractMessageTranscoder;
4-
use sp_core::crypto::AccountId32;
4+
use drink::AccountId32;
55
use ContractIndex::NoContracts;
66

77
use crate::app_state::ContractIndex::CurrentContract;

drink-cli/src/app_state/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::{env, path::PathBuf};
22

33
pub use contracts::{Contract, ContractIndex, ContractRegistry};
4-
use drink::{runtime::MinimalSandbox, session::Session, Sandbox, Weight, DEFAULT_GAS_LIMIT};
5-
use sp_core::crypto::AccountId32;
4+
use drink::{minimal::MinimalSandbox, session::Session, AccountId32, Sandbox, Weight};
65
pub use user_input::UserInput;
76

87
use crate::app_state::output::Output;
@@ -24,7 +23,7 @@ impl Default for ChainInfo {
2423
Self {
2524
block_height: 0,
2625
actor: MinimalSandbox::default_actor(),
27-
gas_limit: DEFAULT_GAS_LIMIT,
26+
gas_limit: MinimalSandbox::default_gas_limit(),
2827
}
2928
}
3029
}

drink-cli/src/app_state/print.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use drink::contracts_api::decode_debug_buffer;
2-
use pallet_contracts::ContractResult;
1+
use drink::{pallet_contracts::ContractResult, sandbox_api::contracts_api::decode_debug_buffer};
32
use ratatui::{
43
style::{Color, Modifier, Style},
54
text::Span,

drink-cli/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::Parser;
2-
use sp_core::crypto::{AccountId32, Ss58Codec};
2+
use drink::{AccountId32, Ss58Codec};
33

44
#[derive(Parser)]
55
pub enum CliCommand {

drink-cli/src/executor/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::env;
55

66
use anyhow::Result;
77
use clap::Parser;
8-
use drink::{sandbox::prelude::*, Weight};
9-
use sp_core::crypto::AccountId32;
8+
use drink::{sandbox_api::prelude::*, AccountId32, Weight};
109

1110
use crate::{app_state::AppState, cli::CliCommand};
1211

drink/Cargo.toml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,13 @@ description = "Minimal sufficient architecture that allows for a fully functiona
1212
[dependencies]
1313
contract-metadata = { workspace = true, optional = true}
1414
contract-transcode = { workspace = true, optional = true }
15-
frame-metadata = { workspace = true }
1615
frame-support = { workspace = true }
1716
frame-system = { workspace = true }
18-
pallet-balances = { workspace = true }
19-
pallet-contracts = { workspace = true }
20-
pallet-contracts-uapi = { workspace = true }
21-
pallet-timestamp = { workspace = true }
2217
parity-scale-codec = { workspace = true }
2318
parity-scale-codec-derive = { workspace = true }
24-
sp-externalities = { workspace = true }
25-
sp-io = { workspace = true }
2619
sp-runtime-interface = { workspace = true }
20+
ink_sandbox = { workspace = true }
2721

28-
paste = { workspace = true }
2922
scale-info = { workspace = true }
3023
serde_json = { workspace = true, optional = true }
3124
thiserror = { workspace = true }

drink/src/lib.rs

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,33 @@
44
#![warn(missing_docs)]
55

66
pub mod errors;
7-
pub mod runtime;
8-
pub mod sandbox;
9-
pub use sandbox::*;
7+
pub mod pallet_contracts_debugging;
108
#[cfg(feature = "session")]
119
pub mod session;
1210

1311
#[cfg(feature = "macros")]
1412
pub use drink_test_macro::{contract_bundle_provider, test};
1513
pub use errors::Error;
16-
use frame_support::traits::fungible::Inspect;
17-
pub use frame_support::{
18-
sp_runtime::{AccountId32, DispatchError},
19-
weights::Weight,
14+
pub use frame_support;
15+
pub use ink_sandbox::{
16+
api as sandbox_api, create_sandbox, pallet_balances, pallet_contracts, pallet_timestamp,
17+
sp_externalities, AccountId32, DispatchError, Sandbox, Ss58Codec, Weight,
2018
};
21-
use frame_system::EventRecord;
22-
use pallet_contracts::{ContractExecResult, ContractInstantiateResult};
2319
#[cfg(feature = "session")]
2420
pub use session::mock::{mock_message, ContractMock, MessageMock, MockedCallResult, Selector};
25-
/// Export pallets that are used in the minimal runtime.
26-
pub use {
27-
frame_support, frame_system, pallet_balances, pallet_contracts, pallet_timestamp, paste,
28-
sp_externalities::Extension, sp_io::TestExternalities,
29-
};
30-
31-
pub use crate::runtime::minimal::{self, MinimalSandbox};
32-
33-
/// Alias for `frame-system`'s `RuntimeCall` type.
34-
pub type RuntimeCall<R> = <R as frame_system::Config>::RuntimeCall;
3521

3622
/// Main result type for the drink crate.
3723
pub type DrinkResult<T> = std::result::Result<T, Error>;
3824

39-
/// Copied from pallet-contracts.
40-
pub type EventRecordOf<Runtime> = EventRecord<
41-
<Runtime as frame_system::Config>::RuntimeEvent,
42-
<Runtime as frame_system::Config>::Hash,
43-
>;
44-
45-
type BalanceOf<R> =
46-
<<R as pallet_contracts::Config>::Currency as Inspect<AccountIdFor<R>>>::Balance;
47-
48-
/// Copied from pallet-contracts.
49-
pub type ContractInstantiateResultFor<Runtime> =
50-
ContractInstantiateResult<AccountIdFor<Runtime>, BalanceOf<Runtime>, EventRecordOf<Runtime>>;
51-
52-
/// Copied from pallet-contracts.
53-
pub type ContractExecResultFor<Runtime> =
54-
ContractExecResult<BalanceOf<Runtime>, EventRecordOf<Runtime>>;
55-
56-
/// Default gas limit.
57-
pub const DEFAULT_GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 1024);
25+
/// Minimal Sandbox runtime used for testing contracts with drink!.
26+
#[allow(missing_docs)]
27+
pub mod minimal {
28+
use ink_sandbox::create_sandbox;
29+
30+
// create_sandbox!(MinimalSandbox);
31+
create_sandbox!(
32+
MinimalSandbox,
33+
(),
34+
crate::pallet_contracts_debugging::DrinkDebug
35+
);
36+
}

drink/src/runtime/pallet_contracts_debugging/intercepting.rs renamed to drink/src/pallet_contracts_debugging/intercepting.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
use pallet_contracts::debug::{CallInterceptor, ExecResult, ExportedFunction};
1+
use ink_sandbox::AccountIdFor;
22
use parity_scale_codec::{Decode, Encode};
33

4-
use crate::runtime::{
4+
use crate::{
5+
pallet_contracts::{
6+
debug::{CallInterceptor, ExecResult, ExportedFunction},
7+
Config,
8+
},
59
pallet_contracts_debugging::{runtime::contract_call_debugger, DrinkDebug},
6-
AccountIdFor,
710
};
811

9-
impl<R: pallet_contracts::Config> CallInterceptor<R> for DrinkDebug {
12+
impl<R: Config> CallInterceptor<R> for DrinkDebug {
1013
fn intercept_call(
1114
contract_address: &AccountIdFor<R>,
1215
entry_point: &ExportedFunction,

drink/src/runtime/pallet_contracts_debugging/runtime.rs renamed to drink/src/pallet_contracts_debugging/runtime.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use parity_scale_codec::Encode;
2-
use sp_externalities::{decl_extension, ExternalitiesExt};
32
use sp_runtime_interface::runtime_interface;
43

4+
use crate::sp_externalities::{decl_extension, ExternalitiesExt};
5+
56
/// Contracts pallet outsources debug callbacks through this runtime interface.
67
///
78
/// Essentially, in our case, it just exposes extensions to the runtime.

drink/src/runtime/pallet_contracts_debugging/tracing.rs renamed to drink/src/pallet_contracts_debugging/tracing.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
use pallet_contracts::{
2-
debug::{CallSpan, ExportedFunction},
3-
ExecReturnValue, Tracing,
4-
};
1+
use ink_sandbox::AccountIdFor;
52

6-
use crate::runtime::{pallet_contracts_debugging::DrinkDebug, AccountIdFor};
3+
use crate::{
4+
pallet_contracts::{
5+
debug::{CallSpan, ExportedFunction},
6+
Config, ExecReturnValue, Tracing,
7+
},
8+
pallet_contracts_debugging::DrinkDebug,
9+
};
710

8-
impl<R: pallet_contracts::Config> Tracing<R> for DrinkDebug {
11+
impl<R: Config> Tracing<R> for DrinkDebug {
912
type CallSpan = DrinkCallSpan<AccountIdFor<R>>;
1013

1114
fn new_call_span(
@@ -36,7 +39,7 @@ pub struct DrinkCallSpan<AccountId> {
3639

3740
impl<AccountId: parity_scale_codec::Encode> CallSpan for DrinkCallSpan<AccountId> {
3841
fn after_call(self, output: &ExecReturnValue) {
39-
crate::runtime::pallet_contracts_debugging::runtime::contract_call_debugger::after_call(
42+
crate::pallet_contracts_debugging::runtime::contract_call_debugger::after_call(
4043
self.contract_address.encode(),
4144
matches!(self.entry_point, ExportedFunction::Call),
4245
self.input_data.to_vec(),

drink/src/runtime.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)