Skip to content

Instantly share code, notes, and snippets.

local function length(elem)
return pandoc.text.len(pandoc.utils.stringify(elem))
end
function insert(doc, inserted, idx, before)
idx = idx or -1
local total_length = length(doc)
if(idx < 0) then
idx = idx + 1 + total_length
end
/// @notice Creates a contract under a deterministic addresses
/// derived only from the deployer's address and the salt.
/// The deployment is a two-step process, first, a proxy is deployed using CREATE2 with
/// the given salt, and then it's called with the bytecode of the deployed contract,
/// the proxy uses it to deploy the contract using regular CREATE.
/// If the deployed contract's constructor reverts, the proxy also reverts and bubbles the error.
/// If the proxy call has a non-zero value, it's passed to the deployed contract's constructor.
/// A deployment can be made either by a contract or an EOA, and over multiple transactions,
/// because the proxy only accepts being called by its deployer, so there's no risk of frontrunning.
/// Each proxy can be used only once, so it's guaranteed to only deploy the contract using nonce 1.
@CodeSandwich
CodeSandwich / Untitled.sol
Created December 16, 2020 18:04
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.7.6+commit.7338295f.js&optimize=true&runs=200&gist=
pragma solidity ^0.7.6;
contract Bench {
uint256 public data;
function increment() public {
uint256 gasUsed = gasleft();
uint256 dataLocal = data;
gasUsed -= gasleft();
dataLocal += gasUsed;
  • mock lifetimes mess, implicit casting everywhere
  • Fn is somewhat limited, no unsafes
  • Common fn for all fn arg counts - fn {} to fn casting is only implicit or fully explicit with all arg types - ergonomics killer, also it breaks if fn is not explicitly requested (but trait is or something). Can't impl anything for fn{}
  • Blanket impls - impl MockUnsafe for Mock conflicts with any impl Mock
fn main() {
unsafe {
mock_0(main, Safe);
mock_unsafe_0(main, Safe);
mock_1(foo, SafeB);
mock_unsafe_1(foo, SafeB);
mock_1(foo, || {static RES: bool = true; MockResult::Return(&RES)});
mock_unsafe_1(foo, || {static RES: bool = true; MockResult::Return(&RES)});
}
}
@CodeSandwich
CodeSandwich / mock traits experiment.rs
Last active April 17, 2019 23:52 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn main() {
unsafe {
Bar.mock_unsafe(foo);
// Bar.mock_unsafe(foo_no); // MUST FAIL
BarNo.mock_unsafe(foo);
BarNo.mock_unsafe(foo_no);
}
// Bar.mock(foo); // MUST FAIL
// Bar.mock_unsafe(foo_no); // MUST FAIL
BarNo.mock(foo);
openapi: "3.0.2"
info:
title: Generic blockchain node REST API
version: 0.0.1
paths:
/v0/tip:
description: Get block ID of the chain tip
get:
responses:
200:
#![cfg_attr(test, feature(proc_macro, proc_macro_mod))]
#[cfg(test)]
extern crate mocktopus;
#[cfg(test)]
use mocktopus::macros::*;
#[cfg(test)]
use mocktopus::mocking::*;
pub struct Node<'a>(Option<&'a Node<'a>>);
#![cfg_attr(test, feature(proc_macro, proc_macro_mod))]
#[cfg(test)] // It's needed only for test runs
extern crate mocktopus;
#[cfg(test)]
mod tests {
use mocktopus::macros::*; // Lack of that line was crashing your code :)
use mocktopus::mocking::*;
// annotating a struct does nothing
RUSTFLAGS='--pretty expanded -Z unstable-options' cargo build