difftreelog
build update evm stubs
in: master
25 files changed
.maintain/scripts/compile_stub.shdiffbeforeafterboth--- /dev/null
+++ b/.maintain/scripts/compile_stub.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+set -eu
+
+dir=$PWD
+
+tmp=$(mktemp -d)
+cd $tmp
+cp $dir/$INPUT input.sol
+solcjs --optimize --bin input.sol
+
+mv input_sol_$(basename $OUTPUT .raw).bin out.bin
+xxd -r -p out.bin out.raw
+
+mv out.raw $dir/$OUTPUT
\ No newline at end of file
.maintain/scripts/generate_api.shdiffbeforeafterboth--- /dev/null
+++ b/.maintain/scripts/generate_api.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+set -eu
+
+tmp=$(mktemp)
+cargo test --package $PACKAGE -- $NAME --exact --nocapture --ignored | tee $tmp
+raw=$(mktemp --suffix .sol)
+sed -n '/=== SNIP START ===/, /=== SNIP END ===/{ /=== SNIP START ===/! { /=== SNIP END ===/! p } }' $tmp > $raw
+formatted=$(mktemp)
+prettier --use-tabs $raw > $formatted
+solhint --fix $formatted
+
+mv $formatted $OUTPUT
\ No newline at end of file
Makefilediffbeforeafterboth--- /dev/null
+++ b/Makefile
@@ -0,0 +1,24 @@
+.PHONY: _eth_codegen
+_eth_codegen:
+
+.PHONY: regenerate_solidity
+regenerate_solidity:
+ PACKAGE=pallet-nft NAME=eth::erc::fungible_iface OUTPUT=./tests/src/eth/api/UniqueFungible.sol ./.maintain/scripts/generate_api.sh
+ PACKAGE=pallet-nft NAME=eth::erc::nft_iface OUTPUT=./tests/src/eth/api/UniqueNFT.sol ./.maintain/scripts/generate_api.sh
+ PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_iface OUTPUT=./tests/src/eth/api/ContractHelpers.sol ./.maintain/scripts/generate_api.sh
+
+ PACKAGE=pallet-nft NAME=eth::erc::fungible_impl OUTPUT=./pallets/nft/src/eth/stubs/UniqueFungible.sol ./.maintain/scripts/generate_api.sh
+ PACKAGE=pallet-nft NAME=eth::erc::nft_impl OUTPUT=./pallets/nft/src/eth/stubs/UniqueNFT.sol ./.maintain/scripts/generate_api.sh
+ PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_impl OUTPUT=./pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol ./.maintain/scripts/generate_api.sh
+
+NFT_EVM_STUBS=./pallets/nft/src/eth/stubs
+CONTRACT_HELPERS_STUBS=./pallets/evm-contract-helpers/src/stubs/
+
+$(NFT_EVM_STUBS)/UniqueFungible.raw: $(NFT_EVM_STUBS)/UniqueFungible.sol
+ INPUT=$< OUTPUT=$@ ./.maintain/scripts/compile_stub.sh
+$(NFT_EVM_STUBS)/UniqueNFT.raw: $(NFT_EVM_STUBS)/UniqueNFT.sol
+ INPUT=$< OUTPUT=$@ ./.maintain/scripts/compile_stub.sh
+$(CONTRACT_HELPERS_STUBS)/ContractHelpers.raw: $(CONTRACT_HELPERS_STUBS)/ContractHelpers.sol
+ INPUT=$< OUTPUT=$@ ./.maintain/scripts/compile_stub.sh
+
+evm_stubs: $(NFT_EVM_STUBS)/UniqueFungible.raw $(NFT_EVM_STUBS)/UniqueNFT.raw $(CONTRACT_HELPERS_STUBS)/ContractHelpers.raw
crates/evm-coder-macros/src/to_log.rsdiffbeforeafterboth1use inflector::cases;2use syn::{Data, DeriveInput, Field, Fields, Ident, Variant, spanned::Spanned};3use std::fmt::Write;4use quote::quote;56use crate::{parse_ident_from_path, parse_ident_from_type, snake_ident_to_screaming};78struct EventField {9 name: Ident,10 camel_name: String,11 ty: Ident,12 indexed: bool,13}1415impl EventField {16 fn try_from(field: &Field) -> syn::Result<Self> {17 let name = field.ident.as_ref().unwrap();18 let ty = parse_ident_from_type(&field.ty, false)?;19 let mut indexed = false;20 for attr in &field.attrs {21 if let Ok(ident) = parse_ident_from_path(&attr.path, false) {22 if ident == "indexed" {23 indexed = true;24 }25 }26 }27 Ok(Self {28 name: name.to_owned(),29 camel_name: cases::camelcase::to_camel_case(&name.to_string()),30 ty: ty.to_owned(),31 indexed,32 })33 }34 fn expand_solidity_argument(&self) -> proc_macro2::TokenStream {35 let camel_name = &self.camel_name;36 let ty = &self.ty;37 quote! {38 <NamedArgument<#ty>>::new(#camel_name)39 }40 }41}4243struct Event {44 name: Ident,45 name_screaming: Ident,46 fields: Vec<EventField>,47 selector: [u8; 32],48 selector_str: String,49}5051impl Event {52 fn try_from(variant: &Variant) -> syn::Result<Self> {53 let name = &variant.ident;54 let name_screaming = snake_ident_to_screaming(name);5556 let named = match &variant.fields {57 Fields::Named(named) => named,58 _ => {59 return Err(syn::Error::new(60 variant.fields.span(),61 "expected named fields",62 ))63 }64 };65 let mut fields = Vec::new();66 for field in &named.named {67 fields.push(EventField::try_from(field)?);68 }69 if fields.iter().filter(|f| f.indexed).count() > 3 {70 return Err(syn::Error::new(71 variant.fields.span(),72 "events can have at most 4 indexed fields (1 indexed field is reserved for event signature)"73 ));74 }75 let mut selector_str = format!("{}(", name);76 for (i, arg) in fields.iter().enumerate() {77 if i != 0 {78 write!(selector_str, ",").unwrap();79 }80 write!(selector_str, "{}", arg.ty).unwrap();81 }82 selector_str.push(')');83 let selector = crate::event_selector_str(&selector_str);8485 Ok(Self {86 name: name.to_owned(),87 name_screaming,88 fields,89 selector,90 selector_str,91 })92 }9394 fn expand_serializers(&self) -> proc_macro2::TokenStream {95 let name = &self.name;96 let name_screaming = &self.name_screaming;97 let fields = self.fields.iter().map(|f| &f.name);9899 let indexed = self.fields.iter().filter(|f| f.indexed).map(|f| &f.name);100 let plain = self.fields.iter().filter(|f| !f.indexed).map(|f| &f.name);101102 quote! {103 Self::#name {#(104 #fields,105 )*} => {106 topics.push(topic::from(Self::#name_screaming));107 #(108 topics.push(#indexed.to_topic());109 )*110 #(111 #plain.abi_write(&mut writer);112 )*113 }114 }115 }116117 fn expand_consts(&self) -> proc_macro2::TokenStream {118 let name_screaming = &self.name_screaming;119 let selector_str = &self.selector_str;120 let selector = &self.selector;121122 quote! {123 #[doc = #selector_str]124 const #name_screaming: [u8; 32] = [#(125 #selector,126 )*];127 }128 }129130 fn expand_solidity_function(&self) -> proc_macro2::TokenStream {131 let name = self.name.to_string();132 let args = self.fields.iter().map(EventField::expand_solidity_argument);133 quote! {134 SolidityEvent {135 name: #name,136 args: (137 #(138 #args,139 )*140 ),141 }142 }143 }144}145146pub struct Events {147 name: Ident,148 events: Vec<Event>,149}150151impl Events {152 pub fn try_from(data: &DeriveInput) -> syn::Result<Self> {153 let name = &data.ident;154 let en = match &data.data {155 Data::Enum(en) => en,156 _ => return Err(syn::Error::new(data.span(), "expected enum")),157 };158 let mut events = Vec::new();159 for variant in &en.variants {160 events.push(Event::try_from(variant)?);161 }162 Ok(Self {163 name: name.to_owned(),164 events,165 })166 }167 pub fn expand(&self) -> proc_macro2::TokenStream {168 let name = &self.name;169170 let consts = self.events.iter().map(Event::expand_consts);171 let serializers = self.events.iter().map(Event::expand_serializers);172 let solidity_name = self.name.to_string();173 let solidity_functions = self.events.iter().map(Event::expand_solidity_function);174175 quote! {176 impl #name {177 #(178 #consts179 )*180181 pub fn generate_solidity_interface(out_set: &mut sp_std::collections::btree_set::BTreeSet<string>, is_impl: bool) {182 use evm_coder::solidity::*;183 use core::fmt::Write;184 let interface = SolidityInterface {185 name: #solidity_name,186 is: &[],187 functions: (#(188 #solidity_functions,189 )*),190 };191 let mut out = string::new();192 out.push_str("// Inline\n");193 let _ = interface.format(is_impl, &mut out);194 out_set.insert(out);195 }196 }197198 #[automatically_derived]199 impl ::evm_coder::events::ToLog for #name {200 fn to_log(&self, contract: address) -> ::ethereum::Log {201 use ::evm_coder::events::ToTopic;202 use ::evm_coder::abi::AbiWrite;203 let mut writer = ::evm_coder::abi::AbiWriter::new();204 let mut topics = Vec::new();205 match self {206 #(207 #serializers,208 )*209 }210 ::ethereum::Log {211 address: contract,212 topics,213 data: writer.finish(),214 }215 }216 }217 }218 }219}1use inflector::cases;2use syn::{Data, DeriveInput, Field, Fields, Ident, Variant, spanned::Spanned};3use std::fmt::Write;4use quote::quote;56use crate::{parse_ident_from_path, parse_ident_from_type, snake_ident_to_screaming};78struct EventField {9 name: Ident,10 camel_name: String,11 ty: Ident,12 indexed: bool,13}1415impl EventField {16 fn try_from(field: &Field) -> syn::Result<Self> {17 let name = field.ident.as_ref().unwrap();18 let ty = parse_ident_from_type(&field.ty, false)?;19 let mut indexed = false;20 for attr in &field.attrs {21 if let Ok(ident) = parse_ident_from_path(&attr.path, false) {22 if ident == "indexed" {23 indexed = true;24 }25 }26 }27 Ok(Self {28 name: name.to_owned(),29 camel_name: cases::camelcase::to_camel_case(&name.to_string()),30 ty: ty.to_owned(),31 indexed,32 })33 }34 fn expand_solidity_argument(&self) -> proc_macro2::TokenStream {35 let camel_name = &self.camel_name;36 let ty = &self.ty;37 let indexed = self.indexed;38 quote! {39 <SolidityEventArgument<#ty>>::new(#indexed, #camel_name)40 }41 }42}4344struct Event {45 name: Ident,46 name_screaming: Ident,47 fields: Vec<EventField>,48 selector: [u8; 32],49 selector_str: String,50}5152impl Event {53 fn try_from(variant: &Variant) -> syn::Result<Self> {54 let name = &variant.ident;55 let name_screaming = snake_ident_to_screaming(name);5657 let named = match &variant.fields {58 Fields::Named(named) => named,59 _ => {60 return Err(syn::Error::new(61 variant.fields.span(),62 "expected named fields",63 ))64 }65 };66 let mut fields = Vec::new();67 for field in &named.named {68 fields.push(EventField::try_from(field)?);69 }70 if fields.iter().filter(|f| f.indexed).count() > 3 {71 return Err(syn::Error::new(72 variant.fields.span(),73 "events can have at most 4 indexed fields (1 indexed field is reserved for event signature)"74 ));75 }76 let mut selector_str = format!("{}(", name);77 for (i, arg) in fields.iter().enumerate() {78 if i != 0 {79 write!(selector_str, ",").unwrap();80 }81 write!(selector_str, "{}", arg.ty).unwrap();82 }83 selector_str.push(')');84 let selector = crate::event_selector_str(&selector_str);8586 Ok(Self {87 name: name.to_owned(),88 name_screaming,89 fields,90 selector,91 selector_str,92 })93 }9495 fn expand_serializers(&self) -> proc_macro2::TokenStream {96 let name = &self.name;97 let name_screaming = &self.name_screaming;98 let fields = self.fields.iter().map(|f| &f.name);99100 let indexed = self.fields.iter().filter(|f| f.indexed).map(|f| &f.name);101 let plain = self.fields.iter().filter(|f| !f.indexed).map(|f| &f.name);102103 quote! {104 Self::#name {#(105 #fields,106 )*} => {107 topics.push(topic::from(Self::#name_screaming));108 #(109 topics.push(#indexed.to_topic());110 )*111 #(112 #plain.abi_write(&mut writer);113 )*114 }115 }116 }117118 fn expand_consts(&self) -> proc_macro2::TokenStream {119 let name_screaming = &self.name_screaming;120 let selector_str = &self.selector_str;121 let selector = &self.selector;122123 quote! {124 #[doc = #selector_str]125 const #name_screaming: [u8; 32] = [#(126 #selector,127 )*];128 }129 }130131 fn expand_solidity_function(&self) -> proc_macro2::TokenStream {132 let name = self.name.to_string();133 let args = self.fields.iter().map(EventField::expand_solidity_argument);134 quote! {135 SolidityEvent {136 name: #name,137 args: (138 #(139 #args,140 )*141 ),142 }143 }144 }145}146147pub struct Events {148 name: Ident,149 events: Vec<Event>,150}151152impl Events {153 pub fn try_from(data: &DeriveInput) -> syn::Result<Self> {154 let name = &data.ident;155 let en = match &data.data {156 Data::Enum(en) => en,157 _ => return Err(syn::Error::new(data.span(), "expected enum")),158 };159 let mut events = Vec::new();160 for variant in &en.variants {161 events.push(Event::try_from(variant)?);162 }163 Ok(Self {164 name: name.to_owned(),165 events,166 })167 }168 pub fn expand(&self) -> proc_macro2::TokenStream {169 let name = &self.name;170171 let consts = self.events.iter().map(Event::expand_consts);172 let serializers = self.events.iter().map(Event::expand_serializers);173 let solidity_name = self.name.to_string();174 let solidity_functions = self.events.iter().map(Event::expand_solidity_function);175176 quote! {177 impl #name {178 #(179 #consts180 )*181182 pub fn generate_solidity_interface(out_set: &mut sp_std::collections::btree_set::BTreeSet<string>, is_impl: bool) {183 use evm_coder::solidity::*;184 use core::fmt::Write;185 let interface = SolidityInterface {186 name: #solidity_name,187 is: &[],188 functions: (#(189 #solidity_functions,190 )*),191 };192 let mut out = string::new();193 out.push_str("// Inline\n");194 let _ = interface.format(is_impl, &mut out);195 out_set.insert(out);196 }197 }198199 #[automatically_derived]200 impl ::evm_coder::events::ToLog for #name {201 fn to_log(&self, contract: address) -> ::ethereum::Log {202 use ::evm_coder::events::ToTopic;203 use ::evm_coder::abi::AbiWrite;204 let mut writer = ::evm_coder::abi::AbiWriter::new();205 let mut topics = Vec::new();206 match self {207 #(208 #serializers,209 )*210 }211 ::ethereum::Log {212 address: contract,213 topics,214 data: writer.finish(),215 }216 }217 }218 }219 }220}crates/evm-coder/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -61,6 +61,29 @@
fn call(&mut self, call: types::Msg<C>) -> execution::Result<AbiWriter>;
}
+#[macro_export]
+macro_rules! generate_stubgen {
+ ($name:ident, $decl:ident, $is_impl:literal) => {
+ #[test]
+ #[ignore]
+ fn $name() {
+ use sp_std::collections::btree_set::BTreeSet;
+ let mut out = BTreeSet::new();
+ $decl::generate_solidity_interface(&mut out, $is_impl);
+ println!("=== SNIP START ===");
+ println!("// SPDX-License-Identifier: OTHER");
+ println!("// This code is automatically generated");
+ println!();
+ println!("pragma solidity >=0.8.0 <0.9.0;");
+ println!();
+ for b in out {
+ println!("{}", b);
+ }
+ println!("=== SNIP END ===");
+ }
+ };
+}
+
#[cfg(test)]
mod tests {
use super::*;
crates/evm-coder/src/solidity.rsdiffbeforeafterboth--- a/crates/evm-coder/src/solidity.rs
+++ b/crates/evm-coder/src/solidity.rs
@@ -117,6 +117,41 @@
}
}
+pub struct SolidityEventArgument<T>(pub bool, &'static str, PhantomData<*const T>);
+
+impl<T> SolidityEventArgument<T> {
+ pub fn new(indexed: bool, name: &'static str) -> Self {
+ Self(indexed, name, Default::default())
+ }
+}
+
+impl<T: SolidityTypeName> SolidityArguments for SolidityEventArgument<T> {
+ fn solidity_name(&self, writer: &mut impl fmt::Write) -> fmt::Result {
+ if !T::is_void() {
+ T::solidity_name(writer)?;
+ if self.0 {
+ write!(writer, " indexed")?;
+ }
+ write!(writer, " {}", self.1)
+ } else {
+ Ok(())
+ }
+ }
+ fn solidity_get(&self, writer: &mut impl fmt::Write) -> fmt::Result {
+ writeln!(writer, "\t\t{};", self.1)
+ }
+ fn solidity_default(&self, writer: &mut impl fmt::Write) -> fmt::Result {
+ T::solidity_default(writer)
+ }
+ fn len(&self) -> usize {
+ if T::is_void() {
+ 0
+ } else {
+ 1
+ }
+ }
+}
+
impl SolidityArguments for () {
fn solidity_name(&self, _writer: &mut impl fmt::Write) -> fmt::Result {
Ok(())
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -1,5 +1,5 @@
use core::marker::PhantomData;
-use evm_coder::{abi::AbiWriter, execution::Result, solidity_interface, types::*};
+use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};
use pallet_evm_coder_substrate::SubstrateRecorder;
use pallet_evm::{ExitReason, ExitRevert, OnCreate, OnMethodCall, PrecompileOutput};
use sp_core::H160;
@@ -14,76 +14,76 @@
#[solidity_interface(name = "ContractHelpers")]
impl<T: Config> ContractHelpers<T> {
- fn contract_owner(&self, contract: address) -> Result<address> {
+ fn contract_owner(&self, contract_address: address) -> Result<address> {
self.0.consume_sload()?;
- Ok(<Owner<T>>::get(contract))
+ Ok(<Owner<T>>::get(contract_address))
}
- fn sponsoring_enabled(&self, contract: address) -> Result<bool> {
+ fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {
self.0.consume_sload()?;
- Ok(<SelfSponsoring<T>>::get(contract))
+ Ok(<SelfSponsoring<T>>::get(contract_address))
}
fn toggle_sponsoring(
&mut self,
caller: caller,
- contract: address,
+ contract_address: address,
enabled: bool,
) -> Result<void> {
self.0.consume_sload()?;
- <Pallet<T>>::ensure_owner(contract, caller)?;
+ <Pallet<T>>::ensure_owner(contract_address, caller)?;
self.0.consume_sstore()?;
- <Pallet<T>>::toggle_sponsoring(contract, enabled);
+ <Pallet<T>>::toggle_sponsoring(contract_address, enabled);
Ok(())
}
fn set_sponsoring_rate_limit(
&mut self,
caller: caller,
- contract: address,
+ contract_address: address,
rate_limit: uint32,
) -> Result<void> {
self.0.consume_sload()?;
- <Pallet<T>>::ensure_owner(contract, caller)?;
+ <Pallet<T>>::ensure_owner(contract_address, caller)?;
self.0.consume_sstore()?;
- <Pallet<T>>::set_sponsoring_rate_limit(contract, rate_limit.into());
+ <Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());
Ok(())
}
- fn allowed(&self, contract: address, user: address) -> Result<bool> {
+ fn allowed(&self, contract_address: address, user: address) -> Result<bool> {
self.0.consume_sload()?;
- Ok(<Pallet<T>>::allowed(contract, user, true))
+ Ok(<Pallet<T>>::allowed(contract_address, user, true))
}
- fn allowlist_enabled(&self, contract: address) -> Result<bool> {
+ fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {
self.0.consume_sload()?;
- Ok(<AllowlistEnabled<T>>::get(contract))
+ Ok(<AllowlistEnabled<T>>::get(contract_address))
}
fn toggle_allowlist(
&mut self,
caller: caller,
- contract: address,
+ contract_address: address,
enabled: bool,
) -> Result<void> {
self.0.consume_sload()?;
- <Pallet<T>>::ensure_owner(contract, caller)?;
+ <Pallet<T>>::ensure_owner(contract_address, caller)?;
self.0.consume_sstore()?;
- <Pallet<T>>::toggle_allowlist(contract, enabled);
+ <Pallet<T>>::toggle_allowlist(contract_address, enabled);
Ok(())
}
fn toggle_allowed(
&mut self,
caller: caller,
- contract: address,
+ contract_address: address,
user: address,
allowed: bool,
) -> Result<void> {
self.0.consume_sload()?;
- <Pallet<T>>::ensure_owner(contract, caller)?;
+ <Pallet<T>>::ensure_owner(contract_address, caller)?;
self.0.consume_sstore()?;
- <Pallet<T>>::toggle_allowed(contract, user, allowed);
+ <Pallet<T>>::toggle_allowed(contract_address, user, allowed);
Ok(())
}
}
@@ -130,7 +130,7 @@
fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {
(contract == &T::ContractAddress::get())
- .then(|| include_bytes!("./stubs/ContractHelpers.bin").to_vec())
+ .then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec())
}
}
@@ -162,3 +162,6 @@
None
}
}
+
+generate_stubgen!(contract_helpers_impl, ContractHelpersCall, true);
+generate_stubgen!(contract_helpers_iface, ContractHelpersCall, false);
pallets/evm-contract-helpers/src/stubs/ContractHelpers.bindiffbeforeafterbothbinary blob — no preview
pallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
+++ b/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
@@ -1,40 +1,92 @@
-contract ContractHelpers {
- uint8 _dummmy = 0;
- address _dummy_addr = 0x0000000000000000000000000000000000000000;
- string stub_error = "this contract does not exists, contract helpers are implemented on substrate chain side";
+// SPDX-License-Identifier: OTHER
+// This code is automatically generated
+
+pragma solidity >=0.8.0 <0.9.0;
+
+// Common stubs holder
+contract Dummy {
+ uint8 dummy;
+ string stub_error = "this contract is implemented in native";
+}
+
+contract ContractHelpers is Dummy {
+ function contractOwner(address contractAddress)
+ public
+ view
+ returns (address)
+ {
+ require(false, stub_error);
+ contractAddress;
+ dummy;
+ return 0x0000000000000000000000000000000000000000;
+ }
+
+ function sponsoringEnabled(address contractAddress)
+ public
+ view
+ returns (bool)
+ {
+ require(false, stub_error);
+ contractAddress;
+ dummy;
+ return false;
+ }
+
+ function toggleSponsoring(address contractAddress, bool enabled) public {
+ require(false, stub_error);
+ contractAddress;
+ enabled;
+ dummy = 0;
+ }
+
+ function setSponsoringRateLimit(address contractAddress, uint32 rateLimit)
+ public
+ {
+ require(false, stub_error);
+ contractAddress;
+ rateLimit;
+ dummy = 0;
+ }
+
+ function allowed(address contractAddress, address user)
+ public
+ view
+ returns (bool)
+ {
+ require(false, stub_error);
+ contractAddress;
+ user;
+ dummy;
+ return false;
+ }
+
+ function allowlistEnabled(address contractAddress)
+ public
+ view
+ returns (bool)
+ {
+ require(false, stub_error);
+ contractAddress;
+ dummy;
+ return false;
+ }
- function contractOwner(address contract_address) public view returns (address) {
- require(false, stub_error);
- contract_address;
- return _dummy_addr;
- }
-
- function sponsoringEnabled(address contract_address) public view returns (bool) {
- require(false, stub_error);
- contract_address;
- _dummmy;
- return false;
- }
-
- function toggleSponsoring(address contract_address, bool enabled) public {
- require(false, stub_error);
- contract_address;
- enabled;
- _dummmy = 0;
- }
-
- function toggleAllowlist(address contract_address, bool enabled) public {
- require(false, stub_error);
- contract_address;
- enabled;
- _dummmy = 0;
- }
-
- function toggleAllowed(address contract_address, address user, bool allowed) public {
- require(false, stub_error);
- contract_address;
- user;
- allowed;
- _dummmy = 0;
- }
-}
\ No newline at end of file
+ function toggleAllowlist(address contractAddress, bool enabled) public {
+ require(false, stub_error);
+ contractAddress;
+ enabled;
+ dummy = 0;
+ }
+
+ function toggleAllowed(
+ address contractAddress,
+ address user,
+ bool allowed
+ ) public {
+ require(false, stub_error);
+ contractAddress;
+ user;
+ allowed;
+ dummy = 0;
+ }
+}
pallets/nft/src/eth/erc.rsdiffbeforeafterboth--- a/pallets/nft/src/eth/erc.rs
+++ b/pallets/nft/src/eth/erc.rs
@@ -1,5 +1,5 @@
use core::char::{decode_utf16, REPLACEMENT_CHARACTER};
-use evm_coder::{ToLog, execution::Result, solidity, solidity_interface, types::*};
+use evm_coder::{ToLog, execution::Result, generate_stubgen, solidity, solidity_interface, types::*};
use nft_data_structs::{CreateItemData, CreateNftData};
use core::convert::TryInto;
use crate::{
@@ -402,32 +402,10 @@
#[solidity_interface(name = "UniqueFungible", is(ERC165, ERC20))]
impl<T: Config> CollectionHandle<T> {}
-
-macro_rules! generate_code {
- ($name:ident, $decl:ident, $is_impl:literal) => {
- #[test]
- #[ignore]
- fn $name() {
- use sp_std::collections::btree_set::BTreeSet;
- let mut out = BTreeSet::new();
- $decl::generate_solidity_interface(&mut out, $is_impl);
- println!("=== SNIP START ===");
- println!("// SPDX-License-Identifier: OTHER");
- println!("// This code is automatically generated with `cargo test --package pallet-nft -- eth::erc::{} --exact --nocapture --ignored`", stringify!(name));
- println!();
- println!("pragma solidity >=0.8.0 <0.9.0;");
- println!();
- for b in out {
- println!("{}", b);
- }
- println!("=== SNIP END ===");
- }
- };
-}
// Not a tests, but code generators
-generate_code!(nft_impl, UniqueNFTCall, true);
-generate_code!(nft_iface, UniqueNFTCall, false);
+generate_stubgen!(nft_impl, UniqueNFTCall, true);
+generate_stubgen!(nft_iface, UniqueNFTCall, false);
-generate_code!(fungible_impl, UniqueFungibleCall, true);
-generate_code!(fungible_iface, UniqueFungibleCall, false);
+generate_stubgen!(fungible_impl, UniqueFungibleCall, true);
+generate_stubgen!(fungible_iface, UniqueFungibleCall, false);
pallets/nft/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/nft/src/eth/mod.rs
+++ b/pallets/nft/src/eth/mod.rs
@@ -96,10 +96,14 @@
.and_then(<CollectionById<T>>::get)
.map(|collection| {
match collection.mode {
- CollectionMode::NFT => include_bytes!("stubs/ERC721.bin") as &[u8],
- CollectionMode::Fungible(_) => include_bytes!("stubs/ERC20.bin") as &[u8],
- CollectionMode::ReFungible => include_bytes!("stubs/ERC1633.bin") as &[u8],
- CollectionMode::Invalid => include_bytes!("stubs/Invalid.bin") as &[u8],
+ CollectionMode::NFT => include_bytes!("stubs/UniqueNFT.raw") as &[u8],
+ CollectionMode::Fungible(_) => {
+ include_bytes!("stubs/UniqueFungible.raw") as &[u8]
+ }
+ CollectionMode::ReFungible => {
+ include_bytes!("stubs/UniqueRefungible.raw") as &[u8]
+ }
+ CollectionMode::Invalid => include_bytes!("stubs/UniqueInvalid.raw") as &[u8],
}
.to_owned()
})
pallets/nft/src/eth/stubs/ERC1633.bindiffbeforeafterboth--- a/pallets/nft/src/eth/stubs/ERC1633.bin
+++ /dev/null
@@ -1 +0,0 @@
-TODO
\ No newline at end of file
pallets/nft/src/eth/stubs/ERC20.bindiffbeforeafterbothbinary blob — no preview
pallets/nft/src/eth/stubs/ERC20.soldiffbeforeafterboth--- a/pallets/nft/src/eth/stubs/ERC20.sol
+++ /dev/null
@@ -1,94 +0,0 @@
-// SPDX-License-Identifier: OTHER
-// This code is automatically generated with `cargo test --package pallet-nft -- eth::erc::name --exact --nocapture --ignored`
-
-pragma solidity >=0.8.0 <0.9.0;
-
-// Common stubs holder
-contract Dummy {
- uint8 dummy;
- string stub_error = "this contract is implemented in native";
-}
-
-// Inline
-contract ERC20Events {
- event Transfer(address from, address to, uint256 value);
- event Approval(address owner, address spender, uint256 value);
-}
-
-// Inline
-contract InlineNameSymbol is Dummy {
- function name() public view returns (string memory) {
- require(false, stub_error);
- dummy;
- return "";
- }
- function symbol() public view returns (string memory) {
- require(false, stub_error);
- dummy;
- return "";
- }
-}
-
-// Inline
-contract InlineTotalSupply is Dummy {
- function totalSupply() public view returns (uint256) {
- require(false, stub_error);
- dummy;
- return 0;
- }
-}
-
-contract ERC165 is Dummy {
- function supportsInterface(uint32 interfaceId) public view returns (bool) {
- require(false, stub_error);
- interfaceId;
- dummy;
- return false;
- }
-}
-
-contract ERC20 is Dummy, InlineNameSymbol, InlineTotalSupply, ERC20Events {
- function decimals() public view returns (uint8) {
- require(false, stub_error);
- dummy;
- return 0;
- }
- function balanceOf(address owner) public view returns (uint256) {
- require(false, stub_error);
- owner;
- dummy;
- return 0;
- }
- function transfer(address to, uint256 amount) public returns (bool) {
- require(false, stub_error);
- to;
- amount;
- dummy = 0;
- return false;
- }
- function transferFrom(address from, address to, uint256 amount) public returns (bool) {
- require(false, stub_error);
- from;
- to;
- amount;
- dummy = 0;
- return false;
- }
- function approve(address spender, uint256 amount) public returns (bool) {
- require(false, stub_error);
- spender;
- amount;
- dummy = 0;
- return false;
- }
- function allowance(address owner, address spender) public view returns (uint256) {
- require(false, stub_error);
- owner;
- spender;
- dummy;
- return 0;
- }
-}
-
-contract UniqueFungible is Dummy, ERC165, ERC20 {
-}
\ No newline at end of file
pallets/nft/src/eth/stubs/ERC721.bindiffbeforeafterbothbinary blob — no preview
pallets/nft/src/eth/stubs/ERC721.soldiffbeforeafterboth--- a/pallets/nft/src/eth/stubs/ERC721.sol
+++ /dev/null
@@ -1,194 +0,0 @@
-// SPDX-License-Identifier: OTHER
-// This code is automatically generated with `cargo test --package pallet-nft -- eth::erc::name --exact --nocapture --ignored`
-
-pragma solidity >=0.8.0 <0.9.0;
-
-// Common stubs holder
-contract Dummy {
- uint8 dummy;
- string stub_error = "this contract is implemented in native";
-}
-
-// Inline
-contract ERC721Events {
- event Transfer(address from, address to, uint256 tokenId);
- event Approval(address owner, address approved, uint256 tokenId);
- event ApprovalForAll(address owner, address operator, bool approved);
-}
-
-// Inline
-contract ERC721MintableEvents {
- event MintingFinished();
-}
-
-// Inline
-contract InlineNameSymbol is Dummy {
- function name() public view returns (string memory) {
- require(false, stub_error);
- dummy;
- return "";
- }
- function symbol() public view returns (string memory) {
- require(false, stub_error);
- dummy;
- return "";
- }
-}
-
-// Inline
-contract InlineTotalSupply is Dummy {
- function totalSupply() public view returns (uint256) {
- require(false, stub_error);
- dummy;
- return 0;
- }
-}
-
-contract ERC165 is Dummy {
- function supportsInterface(uint32 interfaceId) public view returns (bool) {
- require(false, stub_error);
- interfaceId;
- dummy;
- return false;
- }
-}
-
-contract ERC721 is Dummy, ERC165, ERC721Events {
- function balanceOf(address owner) public view returns (uint256) {
- require(false, stub_error);
- owner;
- dummy;
- return 0;
- }
- function ownerOf(uint256 tokenId) public view returns (address) {
- require(false, stub_error);
- tokenId;
- dummy;
- return 0x0000000000000000000000000000000000000000;
- }
- function safeTransferFromWithData(address from, address to, uint256 tokenId, bytes memory data) public {
- require(false, stub_error);
- from;
- to;
- tokenId;
- data;
- dummy = 0;
- }
- function safeTransferFrom(address from, address to, uint256 tokenId) public {
- require(false, stub_error);
- from;
- to;
- tokenId;
- dummy = 0;
- }
- function transferFrom(address from, address to, uint256 tokenId) public {
- require(false, stub_error);
- from;
- to;
- tokenId;
- dummy = 0;
- }
- function approve(address approved, uint256 tokenId) public {
- require(false, stub_error);
- approved;
- tokenId;
- dummy = 0;
- }
- function setApprovalForAll(address operator, bool approved) public {
- require(false, stub_error);
- operator;
- approved;
- dummy = 0;
- }
- function getApproved(uint256 tokenId) public view returns (address) {
- require(false, stub_error);
- tokenId;
- dummy;
- return 0x0000000000000000000000000000000000000000;
- }
- function isApprovedForAll(address owner, address operator) public view returns (address) {
- require(false, stub_error);
- owner;
- operator;
- dummy;
- return 0x0000000000000000000000000000000000000000;
- }
-}
-
-contract ERC721Burnable is Dummy {
- function burn(uint256 tokenId) public {
- require(false, stub_error);
- tokenId;
- dummy = 0;
- }
-}
-
-contract ERC721Enumerable is Dummy, InlineTotalSupply {
- function tokenByIndex(uint256 index) public view returns (uint256) {
- require(false, stub_error);
- index;
- dummy;
- return 0;
- }
- function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) {
- require(false, stub_error);
- owner;
- index;
- dummy;
- return 0;
- }
-}
-
-contract ERC721Metadata is Dummy, InlineNameSymbol {
- function tokenURI(uint256 tokenId) public view returns (string memory) {
- require(false, stub_error);
- tokenId;
- dummy;
- return "";
- }
-}
-
-contract ERC721Mintable is Dummy, ERC721MintableEvents {
- function mintingFinished() public view returns (bool) {
- require(false, stub_error);
- dummy;
- return false;
- }
- function mint(address to, uint256 tokenId) public returns (bool) {
- require(false, stub_error);
- to;
- tokenId;
- dummy = 0;
- return false;
- }
- function mintWithTokenURI(address to, uint256 tokenId, string memory tokenUri) public returns (bool) {
- require(false, stub_error);
- to;
- tokenId;
- tokenUri;
- dummy = 0;
- return false;
- }
- function finishMinting() public returns (bool) {
- require(false, stub_error);
- dummy = 0;
- return false;
- }
-}
-
-contract ERC721UniqueExtensions is Dummy {
- function transfer(address to, uint256 tokenId) public {
- require(false, stub_error);
- to;
- tokenId;
- dummy = 0;
- }
- function nextTokenId() public view returns (uint256) {
- require(false, stub_error);
- dummy;
- return 0;
- }
-}
-
-contract UniqueNFT is Dummy, ERC165, ERC721, ERC721Metadata, ERC721Enumerable, ERC721UniqueExtensions, ERC721Mintable, ERC721Burnable {
-}
\ No newline at end of file
pallets/nft/src/eth/stubs/Invalid.bindiffbeforeafterboth--- a/pallets/nft/src/eth/stubs/Invalid.bin
+++ /dev/null
@@ -1 +0,0 @@
-TODO
\ No newline at end of file
pallets/nft/src/eth/stubs/UniqueFungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/nft/src/eth/stubs/UniqueFungible.soldiffbeforeafterboth--- /dev/null
+++ b/pallets/nft/src/eth/stubs/UniqueFungible.sol
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: OTHER
+// This code is automatically generated
+
+pragma solidity >=0.8.0 <0.9.0;
+
+// Common stubs holder
+contract Dummy {
+ uint8 dummy;
+ string stub_error = "this contract is implemented in native";
+}
+
+// Inline
+contract ERC20Events {
+ event Transfer(address indexed from, address indexed to, uint256 value);
+ event Approval(
+ address indexed owner,
+ address indexed spender,
+ uint256 value
+ );
+}
+
+// Inline
+contract InlineNameSymbol is Dummy {
+ function name() public view returns (string memory) {
+ require(false, stub_error);
+ dummy;
+ return "";
+ }
+
+ function symbol() public view returns (string memory) {
+ require(false, stub_error);
+ dummy;
+ return "";
+ }
+}
+
+// Inline
+contract InlineTotalSupply is Dummy {
+ function totalSupply() public view returns (uint256) {
+ require(false, stub_error);
+ dummy;
+ return 0;
+ }
+}
+
+contract ERC165 is Dummy {
+ function supportsInterface(uint32 interfaceId) public view returns (bool) {
+ require(false, stub_error);
+ interfaceId;
+ dummy;
+ return false;
+ }
+}
+
+contract ERC20 is Dummy, InlineNameSymbol, InlineTotalSupply, ERC20Events {
+ function decimals() public view returns (uint8) {
+ require(false, stub_error);
+ dummy;
+ return 0;
+ }
+
+ function balanceOf(address owner) public view returns (uint256) {
+ require(false, stub_error);
+ owner;
+ dummy;
+ return 0;
+ }
+
+ function transfer(address to, uint256 amount) public returns (bool) {
+ require(false, stub_error);
+ to;
+ amount;
+ dummy = 0;
+ return false;
+ }
+
+ function transferFrom(
+ address from,
+ address to,
+ uint256 amount
+ ) public returns (bool) {
+ require(false, stub_error);
+ from;
+ to;
+ amount;
+ dummy = 0;
+ return false;
+ }
+
+ function approve(address spender, uint256 amount) public returns (bool) {
+ require(false, stub_error);
+ spender;
+ amount;
+ dummy = 0;
+ return false;
+ }
+
+ function allowance(address owner, address spender)
+ public
+ view
+ returns (uint256)
+ {
+ require(false, stub_error);
+ owner;
+ spender;
+ dummy;
+ return 0;
+ }
+}
+
+contract UniqueFungible is Dummy, ERC165, ERC20 {}
pallets/nft/src/eth/stubs/UniqueInvalid.rawdiffbeforeafterboth--- /dev/null
+++ b/pallets/nft/src/eth/stubs/UniqueInvalid.raw
@@ -0,0 +1 @@
+TODO
\ No newline at end of file
pallets/nft/src/eth/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nft/src/eth/stubs/UniqueNFT.soldiffbeforeafterboth--- /dev/null
+++ b/pallets/nft/src/eth/stubs/UniqueNFT.sol
@@ -0,0 +1,253 @@
+// SPDX-License-Identifier: OTHER
+// This code is automatically generated
+
+pragma solidity >=0.8.0 <0.9.0;
+
+// Common stubs holder
+contract Dummy {
+ uint8 dummy;
+ string stub_error = "this contract is implemented in native";
+}
+
+// Inline
+contract ERC721Events {
+ event Transfer(
+ address indexed from,
+ address indexed to,
+ uint256 indexed tokenId
+ );
+ event Approval(
+ address indexed owner,
+ address indexed approved,
+ uint256 indexed tokenId
+ );
+ event ApprovalForAll(
+ address indexed owner,
+ address indexed operator,
+ bool approved
+ );
+}
+
+// Inline
+contract ERC721MintableEvents {
+ event MintingFinished();
+}
+
+// Inline
+contract InlineNameSymbol is Dummy {
+ function name() public view returns (string memory) {
+ require(false, stub_error);
+ dummy;
+ return "";
+ }
+
+ function symbol() public view returns (string memory) {
+ require(false, stub_error);
+ dummy;
+ return "";
+ }
+}
+
+// Inline
+contract InlineTotalSupply is Dummy {
+ function totalSupply() public view returns (uint256) {
+ require(false, stub_error);
+ dummy;
+ return 0;
+ }
+}
+
+contract ERC165 is Dummy {
+ function supportsInterface(uint32 interfaceId) public view returns (bool) {
+ require(false, stub_error);
+ interfaceId;
+ dummy;
+ return false;
+ }
+}
+
+contract ERC721 is Dummy, ERC165, ERC721Events {
+ function balanceOf(address owner) public view returns (uint256) {
+ require(false, stub_error);
+ owner;
+ dummy;
+ return 0;
+ }
+
+ function ownerOf(uint256 tokenId) public view returns (address) {
+ require(false, stub_error);
+ tokenId;
+ dummy;
+ return 0x0000000000000000000000000000000000000000;
+ }
+
+ function safeTransferFromWithData(
+ address from,
+ address to,
+ uint256 tokenId,
+ bytes memory data
+ ) public {
+ require(false, stub_error);
+ from;
+ to;
+ tokenId;
+ data;
+ dummy = 0;
+ }
+
+ function safeTransferFrom(
+ address from,
+ address to,
+ uint256 tokenId
+ ) public {
+ require(false, stub_error);
+ from;
+ to;
+ tokenId;
+ dummy = 0;
+ }
+
+ function transferFrom(
+ address from,
+ address to,
+ uint256 tokenId
+ ) public {
+ require(false, stub_error);
+ from;
+ to;
+ tokenId;
+ dummy = 0;
+ }
+
+ function approve(address approved, uint256 tokenId) public {
+ require(false, stub_error);
+ approved;
+ tokenId;
+ dummy = 0;
+ }
+
+ function setApprovalForAll(address operator, bool approved) public {
+ require(false, stub_error);
+ operator;
+ approved;
+ dummy = 0;
+ }
+
+ function getApproved(uint256 tokenId) public view returns (address) {
+ require(false, stub_error);
+ tokenId;
+ dummy;
+ return 0x0000000000000000000000000000000000000000;
+ }
+
+ function isApprovedForAll(address owner, address operator)
+ public
+ view
+ returns (address)
+ {
+ require(false, stub_error);
+ owner;
+ operator;
+ dummy;
+ return 0x0000000000000000000000000000000000000000;
+ }
+}
+
+contract ERC721Burnable is Dummy {
+ function burn(uint256 tokenId) public {
+ require(false, stub_error);
+ tokenId;
+ dummy = 0;
+ }
+}
+
+contract ERC721Enumerable is Dummy, InlineTotalSupply {
+ function tokenByIndex(uint256 index) public view returns (uint256) {
+ require(false, stub_error);
+ index;
+ dummy;
+ return 0;
+ }
+
+ function tokenOfOwnerByIndex(address owner, uint256 index)
+ public
+ view
+ returns (uint256)
+ {
+ require(false, stub_error);
+ owner;
+ index;
+ dummy;
+ return 0;
+ }
+}
+
+contract ERC721Metadata is Dummy, InlineNameSymbol {
+ function tokenURI(uint256 tokenId) public view returns (string memory) {
+ require(false, stub_error);
+ tokenId;
+ dummy;
+ return "";
+ }
+}
+
+contract ERC721Mintable is Dummy, ERC721MintableEvents {
+ function mintingFinished() public view returns (bool) {
+ require(false, stub_error);
+ dummy;
+ return false;
+ }
+
+ function mint(address to, uint256 tokenId) public returns (bool) {
+ require(false, stub_error);
+ to;
+ tokenId;
+ dummy = 0;
+ return false;
+ }
+
+ function mintWithTokenURI(
+ address to,
+ uint256 tokenId,
+ string memory tokenUri
+ ) public returns (bool) {
+ require(false, stub_error);
+ to;
+ tokenId;
+ tokenUri;
+ dummy = 0;
+ return false;
+ }
+
+ function finishMinting() public returns (bool) {
+ require(false, stub_error);
+ dummy = 0;
+ return false;
+ }
+}
+
+contract ERC721UniqueExtensions is Dummy {
+ function transfer(address to, uint256 tokenId) public {
+ require(false, stub_error);
+ to;
+ tokenId;
+ dummy = 0;
+ }
+
+ function nextTokenId() public view returns (uint256) {
+ require(false, stub_error);
+ dummy;
+ return 0;
+ }
+}
+
+contract UniqueNFT is
+ Dummy,
+ ERC165,
+ ERC721,
+ ERC721Metadata,
+ ERC721Enumerable,
+ ERC721UniqueExtensions,
+ ERC721Mintable,
+ ERC721Burnable
+{}
pallets/nft/src/eth/stubs/UniqueRefungible.rawdiffbeforeafterboth--- /dev/null
+++ b/pallets/nft/src/eth/stubs/UniqueRefungible.raw
@@ -0,0 +1 @@
+TODO
\ No newline at end of file
tests/src/eth/api/ContractHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/ContractHelpers.sol
+++ b/tests/src/eth/api/ContractHelpers.sol
@@ -9,22 +9,35 @@
}
interface ContractHelpers is Dummy {
- function contractOwner(address contr) external view returns (address);
+ function contractOwner(address contractAddress)
+ external
+ view
+ returns (address);
- function sponsoringEnabled(address contr) external view returns (bool);
+ function sponsoringEnabled(address contractAddress)
+ external
+ view
+ returns (bool);
- function toggleSponsoring(address contr, bool enabled) external;
+ function toggleSponsoring(address contractAddress, bool enabled) external;
- function setSponsoringRateLimit(address contr, uint32 rateLimit) external;
+ function setSponsoringRateLimit(address contractAddress, uint32 rateLimit)
+ external;
- function allowed(address contr, address user) external view returns (bool);
+ function allowed(address contractAddress, address user)
+ external
+ view
+ returns (bool);
- function allowlistEnabled(address contr) external view returns (bool);
+ function allowlistEnabled(address contractAddress)
+ external
+ view
+ returns (bool);
- function toggleAllowlist(address contr, bool enabled) external;
+ function toggleAllowlist(address contractAddress, bool enabled) external;
function toggleAllowed(
- address contr,
+ address contractAddress,
address user,
bool allowed
) external;