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: expected literal
--> $DIR/non_literal_parameter.rs:4:38
|
4 | const _: [u8; 32] = ink::blake2x256!(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: [u8; 32] = ink::blake2x256!($input);
assert_eq!(
HASH,
{
let mut output = [0u8; 32];
ir::blake2b_256($input, &mut output);
output
}
);
}};
}
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::u8; 32] = ::ink_lang::blake2x256!("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: [u8; 32] = ink::blake2x256!($input);
assert_eq!(
HASH,
{
let mut output = [0u8; 32];
ir::blake2b_256($input.as_bytes(), &mut output);
output
}
);
}};
}
fn main() {
assert_macro_eq!("");
assert_macro_eq!("Hello, World!");
assert_macro_eq!("message");
assert_macro_eq!("constructor");
}
use ink_lang as ink;
const _: u32 = ink::selector_bytes!(true);
fn main() {}
error: expected string or byte string literal as input. found Bool(LitBool { value: true })
--> $DIR/invalid_parameter_type_01.rs:3:37
|
3 | const _: u32 = ink::selector_bytes!(true);
| ^^^^
use ink_lang as ink;
const _: u32 = ink::selector_bytes!(42);
fn main() {}
error: expected string or byte string literal as input. found Int(LitInt { token: 42 })
--> $DIR/invalid_parameter_type_02.rs:3:37
|
3 | const _: u32 = ink::selector_bytes!(42);
| ^^
use ink_lang as ink;
const _: u32 = ink::selector_bytes!();
fn main() {}
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_bytes!();
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `ink::selector_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
use ink_lang as ink;
const INPUT: &str = "test";
const _: u32 = ink::selector_bytes!(INPUT);
fn main() {}
error: expected string or byte string literal as input: expected literal
--> $DIR/non_literal_parameter.rs:4:37
|
4 | const _: u32 = ink::selector_bytes!(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: [u8; 4] = ink::selector_bytes!($input);
assert_eq!(
HASH,
*ir::Selector::new($input).as_bytes(),
);
}};
}
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::u8; 4] = ::ink_lang::selector_bytes!("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: [u8; 4] = ink::selector_bytes!($input);
assert_eq!(
HASH,
*ir::Selector::new($input.as_bytes()).as_bytes(),
);
}};
}
fn main() {
assert_macro_eq!("");
assert_macro_eq!("Hello, World!");
assert_macro_eq!("message");
assert_macro_eq!("constructor");
}
use ink_lang as ink;
const _: u32 = ink::selector_id!(true);
fn main() {}
error: expected string or byte string literal as input. found Bool(LitBool { value: true })
--> $DIR/invalid_parameter_type_01.rs:3:34
|
3 | const _: u32 = ink::selector_id!(true);
| ^^^^
use ink_lang as ink;
const _: u32 = ink::selector_id!(42);
fn main() {}
error: expected string or byte string literal as input. found Int(LitInt { token: 42 })
--> $DIR/invalid_parameter_type_02.rs:3:34
|
3 | const _: u32 = ink::selector_id!(42);
| ^^
use ink_lang as ink;
const _: u32 = ink::selector_id!();
fn main() {}
Supports Markdown
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