Unverified Commit 5c5d17df authored by Hero Bird's avatar Hero Bird Committed by GitHub

ink! abi followup (#168)

* [examples] remove unneeded dependencies

* [cli] template: remove unneeded dependencies

* [*] make test-env a default feature

* [core] no longer export impl_empty_flush_for macro

* [scripts] add usage docs to check-workspace

* [readme] add section about scripts

* [core] add lib.rs docs

* [core] simple Cargo.toml formatting

* [ci] use latest nightly-2019-08-13

* [ci] upload kcov results after workspace checks

* [scripts] fix the banner not being printed

* Update README.md
Co-Authored-By: Andrew Jones's avatarAndrew Jones <ascjones@gmail.com>

* Update core/src/lib.rs
Co-Authored-By: Andrew Jones's avatarAndrew Jones <ascjones@gmail.com>
parent fa6b0065
...@@ -7,7 +7,7 @@ rust: ...@@ -7,7 +7,7 @@ rust:
# - stable # - stable
# - beta # - beta
- nightly - nightly
- nightly-2019-08-09 - nightly-2019-08-13
matrix: matrix:
allow_failures: allow_failures:
...@@ -65,16 +65,19 @@ script: ...@@ -65,16 +65,19 @@ script:
./scripts/check-workspace.sh ./scripts/check-workspace.sh
check_workspace=$? check_workspace=$?
./scripts/check-examples.sh if [ $check_workspace -eq 0 ]
check_examples=$?
if [ $check_examples -eq 0 ] && [ $check_workspace -eq 0 ]
then then
# Execute and upload kcov results # Execute and upload kcov results
cargo kcov --verbose --coveralls --all --no-clean-rebuild cargo kcov --verbose --coveralls --all --no-clean-rebuild
kcov=$? kcov=$?
bash <(curl -s https://codecov.io/bash) bash <(curl -s https://codecov.io/bash)
fi
./scripts/check-examples.sh
check_examples=$?
if [ $check_examples -eq 0 ] && [ $check_workspace -eq 0 ]
then
echo "All checks have passed!" echo "All checks have passed!"
exit 0 exit 0
else else
......
...@@ -35,6 +35,15 @@ ink! is an [eDSL](https://wiki.haskell.org/Embedded_domain_specific_language) to ...@@ -35,6 +35,15 @@ ink! is an [eDSL](https://wiki.haskell.org/Embedded_domain_specific_language) to
|-----------|------------|-------------| |-----------|------------|-------------|
| [![][H1]][H2] | [![][F1]][F2] | [![][G1]][G2] | | [![][H1]][H2] | [![][F1]][F2] | [![][G1]][G2] |
### Scripts
Use the scripts provided under `scripts` directory in order to run checks on either the workspace or all examples. Please do this before pushing work in a PR.
### Testing
Off-chain testing is done by `cargo test`.
If you want to test all workspace crates, do `cargo test --all`.
## Example ## Example
Below is an example using ink! demonstrating a simple Flipper smart contract Below is an example using ink! demonstrating a simple Flipper smart contract
...@@ -44,7 +53,7 @@ that has a boolean state that can be flipped or returned. ...@@ -44,7 +53,7 @@ that has a boolean state that can be flipped or returned.
contract! { contract! {
/// Specify concrete implementation of contract environment types /// Specify concrete implementation of contract environment types
#![env = ink_core::env::DefaultSrmlTypes] #![env = ink_core::env::DefaultSrmlTypes]
/// Flips its state between `true` and `false`. /// Flips its state between `true` and `false`.
struct Flipper { struct Flipper {
/// The current state of our flag. /// The current state of our flag.
......
...@@ -11,7 +11,6 @@ ink_model = { git = "https://github.com/paritytech/ink", package = "ink_model", ...@@ -11,7 +11,6 @@ ink_model = { git = "https://github.com/paritytech/ink", package = "ink_model",
ink_lang = { git = "https://github.com/paritytech/ink", package = "ink_lang", default-features = false } ink_lang = { git = "https://github.com/paritytech/ink", package = "ink_lang", default-features = false }
scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] } scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true } type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true }
[lib] [lib]
...@@ -42,8 +41,6 @@ test-env = [ ...@@ -42,8 +41,6 @@ test-env = [
ink-generate-abi = [ ink-generate-abi = [
"std", "std",
"ink_abi", "ink_abi",
"serde",
"serde_json",
"type-metadata", "type-metadata",
"ink_core/ink-generate-abi", "ink_core/ink-generate-abi",
] ]
......
...@@ -21,12 +21,12 @@ include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"] ...@@ -21,12 +21,12 @@ include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"]
ink_abi = { path = "../abi/", default-features = false, features = ["derive"], optional = true } ink_abi = { path = "../abi/", default-features = false, features = ["derive"], optional = true }
ink_alloc = { path = "../alloc/", default-features = false } ink_alloc = { path = "../alloc/", default-features = false }
ink_utils = { path = "../utils/", default-features = false } ink_utils = { path = "../utils/", default-features = false }
scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive", "full"] }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true } type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true }
[features] [features]
default = ["std"] default = ["test-env"]
test-env = ["std"] test-env = ["std"]
std = [ std = [
"ink_abi/std", "ink_abi/std",
......
...@@ -21,7 +21,6 @@ use core::{ ...@@ -21,7 +21,6 @@ use core::{
use crate::{ use crate::{
env::EnvTypes, env::EnvTypes,
impl_empty_flush_for,
storage::Flush, storage::Flush,
}; };
use scale::{ use scale::{
...@@ -116,4 +115,10 @@ pub type Moment = u64; ...@@ -116,4 +115,10 @@ pub type Moment = u64;
/// The default SRML blocknumber type. /// The default SRML blocknumber type.
pub type BlockNumber = u64; pub type BlockNumber = u64;
impl_empty_flush_for!(AccountId, Hash); impl Flush for AccountId {
fn flush(&mut self) {}
}
impl Flush for Hash {
fn flush(&mut self) {}
}
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with ink!. If not, see <http://www.gnu.org/licenses/>. // along with ink!. If not, see <http://www.gnu.org/licenses/>.
//! The `ink_core` utilities used by all ink! smart contracts.
//!
//! Mainly provides entities to work on a contract's storage
//! as well as high-level collections on top of those.
//! Also provides environmental utilities, such as storage allocators,
//! FFI to interface with SRML contracts and a primitive blockchain
//! emulator for simple off-chain testing.
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![deny( #![deny(
bad_style, bad_style,
......
...@@ -42,7 +42,6 @@ pub trait Flush { ...@@ -42,7 +42,6 @@ pub trait Flush {
fn flush(&mut self); fn flush(&mut self);
} }
#[macro_export]
macro_rules! impl_empty_flush_for { macro_rules! impl_empty_flush_for {
( $($ty:ty),* ) => { ( $($ty:ty),* ) => {
$( $(
......
...@@ -11,7 +11,6 @@ ink_model = { path = "../../../model", default-features = false } ...@@ -11,7 +11,6 @@ ink_model = { path = "../../../model", default-features = false }
ink_lang = { path = "../../../lang", default-features = false } ink_lang = { path = "../../../lang", default-features = false }
scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] } scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true } type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true }
[lib] [lib]
...@@ -32,7 +31,6 @@ std = [ ...@@ -32,7 +31,6 @@ std = [
"ink_lang/std", "ink_lang/std",
"type-metadata/std", "type-metadata/std",
"scale/std", "scale/std",
"serde/std",
] ]
test-env = [ test-env = [
"std", "std",
...@@ -43,7 +41,6 @@ test-env = [ ...@@ -43,7 +41,6 @@ test-env = [
ink-generate-abi = [ ink-generate-abi = [
"std", "std",
"ink_abi", "ink_abi",
"serde",
"type-metadata", "type-metadata",
"ink_core/ink-generate-abi", "ink_core/ink-generate-abi",
] ]
......
...@@ -11,8 +11,6 @@ ink_model = { path = "../../../model", default-features = false } ...@@ -11,8 +11,6 @@ ink_model = { path = "../../../model", default-features = false }
ink_lang = { path = "../../../lang", default-features = false } ink_lang = { path = "../../../lang", default-features = false }
scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] } scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
serde_json = { version = "1.0", default-features = false, optional = true }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true } type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true }
[lib] [lib]
...@@ -32,7 +30,6 @@ std = [ ...@@ -32,7 +30,6 @@ std = [
"ink_model/std", "ink_model/std",
"ink_lang/std", "ink_lang/std",
"scale/std", "scale/std",
"serde/std",
"type-metadata/std", "type-metadata/std",
] ]
test-env = [ test-env = [
...@@ -44,8 +41,6 @@ test-env = [ ...@@ -44,8 +41,6 @@ test-env = [
ink-generate-abi = [ ink-generate-abi = [
"std", "std",
"ink_abi", "ink_abi",
"serde",
"serde_json",
"type-metadata", "type-metadata",
"ink_core/ink-generate-abi", "ink_core/ink-generate-abi",
] ]
......
...@@ -11,8 +11,6 @@ ink_model = { path = "../../../model", default-features = false } ...@@ -11,8 +11,6 @@ ink_model = { path = "../../../model", default-features = false }
ink_lang = { path = "../../../lang", default-features = false } ink_lang = { path = "../../../lang", default-features = false }
scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] } scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
serde_json = { version = "1.0", default-features = false, optional = true }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true } type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true }
[lib] [lib]
...@@ -32,7 +30,6 @@ std = [ ...@@ -32,7 +30,6 @@ std = [
"ink_model/std", "ink_model/std",
"ink_lang/std", "ink_lang/std",
"scale/std", "scale/std",
"serde/std",
"type-metadata/std", "type-metadata/std",
] ]
test-env = [ test-env = [
...@@ -44,8 +41,6 @@ test-env = [ ...@@ -44,8 +41,6 @@ test-env = [
ink-generate-abi = [ ink-generate-abi = [
"std", "std",
"ink_abi", "ink_abi",
"serde",
"serde_json",
"type-metadata", "type-metadata",
"ink_core/ink-generate-abi", "ink_core/ink-generate-abi",
] ]
......
...@@ -11,8 +11,6 @@ ink_model = { path = "../../../model", default-features = false } ...@@ -11,8 +11,6 @@ ink_model = { path = "../../../model", default-features = false }
ink_lang = { path = "../../../lang", default-features = false } ink_lang = { path = "../../../lang", default-features = false }
scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] } scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
serde_json = { version = "1.0", default-features = false, optional = true }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true } type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true }
[lib] [lib]
...@@ -32,7 +30,6 @@ std = [ ...@@ -32,7 +30,6 @@ std = [
"ink_model/std", "ink_model/std",
"ink_lang/std", "ink_lang/std",
"scale/std", "scale/std",
"serde/std",
"type-metadata/std", "type-metadata/std",
] ]
test-env = [ test-env = [
...@@ -44,8 +41,6 @@ test-env = [ ...@@ -44,8 +41,6 @@ test-env = [
ink-generate-abi = [ ink-generate-abi = [
"std", "std",
"ink_abi", "ink_abi",
"serde",
"serde_json",
"type-metadata", "type-metadata",
"ink_core/ink-generate-abi", "ink_core/ink-generate-abi",
] ]
......
...@@ -39,7 +39,7 @@ name = "ink_lang" ...@@ -39,7 +39,7 @@ name = "ink_lang"
proc-macro = true proc-macro = true
[features] [features]
default = ["std"] default = ["test-env"]
std = [ std = [
"ink_utils/std", "ink_utils/std",
"ink_model/std", "ink_model/std",
...@@ -49,5 +49,6 @@ std = [ ...@@ -49,5 +49,6 @@ std = [
"serde/std", "serde/std",
] ]
test-env = [ test-env = [
"std",
"ink_model/test-env", "ink_model/test-env",
] ]
\ No newline at end of file
...@@ -18,7 +18,7 @@ ink_core = { path = "../core", default-features = false } ...@@ -18,7 +18,7 @@ ink_core = { path = "../core", default-features = false }
scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive", "full"] } scale = { package = "parity-scale-codec", version = "1.0", default-features = false, features = ["derive", "full"] }
[features] [features]
default = ["std"] default = ["test-env"]
test-env = [ test-env = [
"std", "std",
"ink_core/test-env", "ink_core/test-env",
......
...@@ -48,8 +48,9 @@ for example in $(ls examples/lang); do ...@@ -48,8 +48,9 @@ for example in $(ls examples/lang); do
fi fi
done done
banner="---------------"
echo "Example Results" echo "Example Results"
echo "---------------" echo "$banner"
for entry in ${!results_wasm[@]}; do for entry in ${!results_wasm[@]}; do
echo "- $entry (wasm): ${results_wasm[$entry]}" echo "- $entry (wasm): ${results_wasm[$entry]}"
echo "- $entry (test): ${results_test[$entry]}" echo "- $entry (test): ${results_test[$entry]}"
...@@ -59,9 +60,10 @@ echo "" ...@@ -59,9 +60,10 @@ echo ""
if [ $all_checks_passed -eq 0 ] if [ $all_checks_passed -eq 0 ]
then then
echo "examples: All checks passed" echo "examples: All checks passed"
echo "$banner"
exit 0 exit 0
else else
echo "examples: Some checks failed" echo "examples: Some checks failed"
echo "$banner"
exit 1 exit 1
fi fi
echo "---------------"
#!/bin/bash #!/bin/bash
# Run this script from the workspace root!
#
# This script iterates through all crates in the workspace and runs
# the most important actions to verify integrity and control quality.
#
# - compile under different setups
# - check formatting according to our house rules
# - run a linter (clippy) under different setups
# - run all tests
# - build Wasm blobs
#
# Afterwards the script prints out a summary report.
#
# Exits with `0` if all tests completed successfully or `1` otherwise.
declare -A results declare -A results
cargo check --verbose --all --all-features cargo check --verbose --all --all-features
...@@ -24,9 +39,10 @@ cargo build --verbose --all --no-default-features --release --target=wasm32-unkn ...@@ -24,9 +39,10 @@ cargo build --verbose --all --no-default-features --release --target=wasm32-unkn
results["build_wasm"]=$? results["build_wasm"]=$?
all_checks_passed=0 all_checks_passed=0
banner="-----------------"
echo "Workspace Results" echo "Workspace Results"
echo "-----------------" echo "$banner"
for entry in ${!results[@]}; do for entry in ${!results[@]}; do
result_str="" result_str=""
if [ ${results[$entry]} -eq 0 ] if [ ${results[$entry]} -eq 0 ]
...@@ -42,9 +58,10 @@ echo "" ...@@ -42,9 +58,10 @@ echo ""
if [ $all_checks_passed -eq 0 ] if [ $all_checks_passed -eq 0 ]
then then
echo "workspace: All checks passed" echo "workspace: All checks passed"
echo "$banner"
exit 0 exit 0
else else
echo "workspace: Some checks failed" echo "workspace: Some checks failed"
echo "$banner"
exit 1 exit 1
fi fi
echo "-----------------"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment