Unverified Commit bd4b51e3 authored by Robin Freyler's avatar Robin Freyler Committed by GitHub
Browse files

Implement selector_id!, selector_bytes! and blake2x256! macros (#947)

* add selector_id! and selector_bytes! proc macros

* implement blake2x256! macro

* re-export blake2x256! macro from ink_lang crate

* apply rustfmt

* add BLAKE2b to hunspell dictionary

* add UI tests for blake2x256! macro

* improve span for non-literal inputs to blake2x256! macro

* add non-literal input failure UI test to blake2x256! macro

* improve error span for non-literal selector_{id,bytes}! macro inputs

* rename UI test blake2x256 -> blake2x256_macro

* rename UI test

* add UI tests for selector_id! proc. macro

* fix UI test

* fix UI test expectation

* add UI tests for seletor_bytes! macro

* make flaky and broken codecov CI happy again ...
parent 7c19f63e
Pipeline #160560 failed with stages
in 9 minutes and 22 seconds
error: expected string or byte string literal as input: unexpected end of input, expected literal
--> $DIR/missing_parameter.rs:3:16
|
3 | const _: u32 = ink::selector_id!();
| ^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `ink::selector_id` (in Nightly builds, run with -Z macro-backtrace for more info)
use ink_lang as ink;
const INPUT: &str = "test";
const _: u32 = ink::selector_id!(INPUT);
fn main() {}
error: expected string or byte string literal as input: expected literal
--> $DIR/non_literal_parameter.rs:4:34
|
4 | const _: u32 = ink::selector_id!(INPUT);
| ^^^^^
use ink_lang as ink;
use ink_lang_ir as ir;
macro_rules! assert_macro_eq {
( $input:literal ) => {{
// We put it into a constant to verify that the computation is constant.
const HASH: u32 = ink::selector_id!($input);
assert_eq!(
HASH,
ir::Selector::new($input).into_be_u32(),
);
}};
}
fn main() {
assert_macro_eq!(b"");
assert_macro_eq!(b"Hello, World!");
assert_macro_eq!(b"message");
assert_macro_eq!(b"constructor");
}
#![no_implicit_prelude]
const _: ::core::primitive::u32 = ::ink_lang::selector_id!("test");
fn main() {}
use ink_lang as ink;
use ink_lang_ir as ir;
macro_rules! assert_macro_eq {
( $input:literal ) => {{
// We put it into a constant to verify that the computation is constant.
const HASH: u32 = ink::selector_id!($input);
assert_eq!(
HASH,
ir::Selector::new($input.as_bytes()).into_be_u32(),
);
}};
}
fn main() {
assert_macro_eq!("");
assert_macro_eq!("Hello, World!");
assert_macro_eq!("message");
assert_macro_eq!("constructor");
}
......@@ -78,8 +78,11 @@ pub use self::{
};
pub use ::static_assertions;
pub use ink_lang_macro::{
blake2x256,
chain_extension,
contract,
selector_bytes,
selector_id,
test,
trait_definition,
};
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