Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vesting precompile #661

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1148335
try precompile vesting without custom pallet
luispdm Jul 8, 2024
bb2e0f4
move docstring comments on top of VestingInfo struct; add address
luispdm Jul 8, 2024
08fa287
contract address changed to 0x...407
luispdm Jul 8, 2024
0f18be4
vestOther; comments in vesting.sol
luispdm Jul 9, 2024
6137eb0
Merge remote-tracking branch 'origin/main' into feature/vesting-preco…
luispdm Jul 9, 2024
02bba6f
implement vesting
luispdm Jul 9, 2024
3cab44e
improve @return comment of vesting fn in Vesting.sol
luispdm Jul 9, 2024
00eb073
change precompile address to `...406`
luispdm Jul 9, 2024
fb0366d
vesting precompile mock and start tests
luispdm Jul 9, 2024
482aa39
Vesting .json contract + `406` added to spec files
luispdm Jul 9, 2024
80a9c35
selector tests
magecnion Jul 9, 2024
b19923b
test vesting fn
magecnion Jul 10, 2024
e2222ce
test vest fn
magecnion Jul 10, 2024
cbfd5a3
test vest_other fn
magecnion Jul 10, 2024
584d24b
fix clippy warnings
magecnion Jul 10, 2024
ced214e
replace std `vec!` for `sp_std`'s `Vec::new()`
luispdm Jul 11, 2024
cd25737
wip
magecnion Jul 11, 2024
b8949eb
integrate tests and mocks with pallet wrapper; pallet wrapper with de…
luispdm Jul 11, 2024
9e46f91
add first tests
magecnion Jul 11, 2024
af9f083
add more tests
magecnion Jul 11, 2024
95b566f
vest_other precompile benchmark; fix warnings; upload weights for two…
luispdm Jul 11, 2024
5090788
add more tests
magecnion Jul 11, 2024
700a0e6
fix test
magecnion Jul 11, 2024
9198344
use revert util function in test-evolution
magecnion Jul 11, 2024
a8e74db
fix tests
magecnion Jul 11, 2024
1b95c88
fmt
magecnion Jul 11, 2024
e3f19a9
Merge branch 'test/e2e-vesting-precompile' into feature/vesting-preco…
magecnion Jul 11, 2024
fd67d54
fmt
magecnion Jul 11, 2024
e76ba40
fix test
magecnion Jul 11, 2024
fdbc2db
vesting benchmark + weights
luispdm Jul 12, 2024
c0f10ec
added fmt check
asiniscalchi Jul 15, 2024
3d08bca
chains specs have not to change
asiniscalchi Jul 15, 2024
cdfc406
add precompile gas cost
magecnion Jul 15, 2024
7eb3e21
fmt
magecnion Jul 15, 2024
e626a22
Merge pull request #666 from freeverseio/feature/add_fmt_check
asiniscalchi Jul 16, 2024
4666c7e
Merge pull request #667 from freeverseio/test/vesting-precompile-has-…
asiniscalchi Jul 16, 2024
005e929
remove wrong CI workflow
asiniscalchi Jul 16, 2024
a0fcec3
generalize wrapper pallet to reuse it with multiple precompiles
luispdm Jul 16, 2024
ef0cb5a
allow directive: clippy ignore multiple bound locations in benchmarks
luispdm Jul 17, 2024
5cd220e
restore lint-e2e job
luispdm Jul 17, 2024
91c6758
lint-e2e checkout code
luispdm Jul 17, 2024
5ad6488
move vesting precompile to pallets folder
luispdm Jul 17, 2024
934cc5b
cargo fmt
luispdm Jul 17, 2024
b71e41d
Merge remote-tracking branch 'origin/main' into feature/vesting-preco…
luispdm Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ jobs:
- name: Check clippy
run: |
SKIP_WASM_BUILD=1 cargo clippy --all-targets --workspace --features runtime-benchmarks --features try-runtime -- -D warnings
lint-e2e:
runs-on:
group: laos
labels: ubuntu-16-cores
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: |
npm install
working-directory: ./e2e-tests
- name: Run lint
run: |
npm run fmt-check
working-directory: ./e2e-tests

test:
runs-on:
group: laos
Expand Down
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ substrate-fixed = { git = "https://github.com/encointer/substrate-fixed", defaul
pallet-laos-evolution = { path = "./pallets/laos-evolution", default-features = false }
pallet-asset-metadata-extender = { path = "./pallets/asset-metadata-extender", default-features = false }
pallet-parachain-staking = { path = "./pallets/parachain-staking", default-features = false }
pallet-benchmark = { path = "./pallets/benchmark", default-features = false}

# Primitives
laos-primitives = { path = "./primitives", default-features = false }
Expand Down
10 changes: 10 additions & 0 deletions e2e-tests/compile_contracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# we need to move .sol files under /contracts folder so that truffle works properly
cp -r ../pallets/laos-evolution/src/precompiles/evolution_collection_factory/contracts contracts
cp -r ../pallets/laos-evolution/src/precompiles/evolution_collection/contracts contracts
cp -r ../pallets/asset-metadata-extender/src/precompiles/asset_metadata_extender/contracts contracts
cp -r ../pallets/benchmark/src/precompiles/vesting/contracts contracts

truffle compile
rm -rf contracts
2 changes: 1 addition & 1 deletion e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"fmt-check": "prettier ./tests --check",
"fmt": "prettier ./tests --write",
"build": "cp -r ../pallets/laos-evolution/src/precompiles/evolution_collection_factory/contracts contracts && cp -r ../pallets/laos-evolution/src/precompiles/evolution_collection/contracts contracts && cp -r ../pallets/asset-metadata-extender/src/precompiles/asset_metadata_extender/contracts contracts && truffle compile && rm -rf contracts",
"build": "./compile_contracts.sh",
"test": "mocha -r ts-node/register -t 70000 --grep '@qa' --invert 'tests/**/*.ts'",
"qa": "mocha -r ts-node/register -t 200000 --grep '@qa' 'tests/**/*.ts'",
"test-sql": "FRONTIER_BACKEND_TYPE='sql' mocha -r ts-node/register 'tests/**/*.ts'"
Expand Down
15 changes: 9 additions & 6 deletions e2e-tests/tests/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AbiItem } from "web3-utils";
import AssetMetadataExtender from "../build/contracts/AssetMetadataExtender.json";
import EvolutionCollection from "../build/contracts/EvolutionCollection.json";
import EvolutionCollectionFactory from "../build/contracts/EvolutionCollectionFactory.json";
import Vesting from "../build/contracts/Vesting.json";

// Node config
export const RUNTIME_SPEC_NAME = "laos";
Expand All @@ -21,18 +22,16 @@ export const ETH_BLOCK_GAS_LIMIT = 15000000; // The same configuration as runtim
export const GAS_LIMIT = ETH_BLOCK_GAS_LIMIT - 10000000;

// LAOS Evolution Contract
export const EVOLUTION_COLLETION_FACTORY_ABI = EvolutionCollectionFactory.abi as AbiItem[];
export const EVOLUTION_COLLECTION_FACTORY_ABI = EvolutionCollectionFactory.abi as AbiItem[];
export const EVOLUTION_COLLECTION_ABI = EvolutionCollection.abi as AbiItem[];
export const CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000403";
export const EVOLUTION_COLLECTION_FACTORY_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000403";
export const SELECTOR_LOG_NEW_COLLECTION = "0x5b84d9550adb7000df7bee717735ecd3af48ea3f66c6886d52e8227548fb228c";
export const SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI =
"0xa7135052b348b0b4e9943bae82d8ef1c5ac225e594ef4271d12f0744cfc98348";
export const SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI =
"0xdde18ad2fe10c12a694de65b920c02b851c382cf63115967ea6f7098902fa1c8";
export const SELECTOR_LOG_OWNERSHIP_TRANSFERRED =
"0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0";
export const SELECTOR_LOG_PUBLIC_MINTING_ENABLED =
"0x8ff3deee4c40ab085dd8d7d0c848cb5295e4ab5faa32e5b60e3936cf1bdc77bf";
export const SELECTOR_LOG_OWNERSHIP_TRANSFERRED = "0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0";
export const SELECTOR_LOG_PUBLIC_MINTING_ENABLED = "0x8ff3deee4c40ab085dd8d7d0c848cb5295e4ab5faa32e5b60e3936cf1bdc77bf";
export const SELECTOR_LOG_PUBLIC_MINTING_DISABLED =
"0xebe230014056e5cb4ca6d8e534189bf5bfb0759489f16170654dce7c014b6699";

Expand All @@ -44,6 +43,10 @@ export const SELECTOR_LOG_EXTENDED_UL_WITH_EXTERNAL_URI =
export const SELECTOR_LOG_UPDATED_EXTENDED_UL_WITH_EXTERNAL_URI =
"0xe7ebe38355126fe0c3eab0ec03eb1b94ff501458a80713c9eb8b737334a651ff";

// Vesting contract
export const VESTING_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000406";
export const VESTING_ABI = Vesting.abi as AbiItem[];

// Constants
export const MAX_U96 = new BN("79228162514264337593543950336"); // 2^96 - 1
export const REVERT_BYTECODE = "0x60006000fd";
40 changes: 23 additions & 17 deletions e2e-tests/tests/test-create-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { expect } from "chai";
import { step } from "mocha-steps";
import Contract from "web3-eth-contract";
import {
CONTRACT_ADDRESS,
EVOLUTION_COLLETION_FACTORY_ABI,
EVOLUTION_COLLECTION_FACTORY_CONTRACT_ADDRESS,
EVOLUTION_COLLECTION_FACTORY_ABI,
GAS_LIMIT,
GAS_PRICE,
FAITH,
Expand All @@ -21,18 +21,22 @@ describeWithExistingNode("Frontier RPC (Create Collection)", (context) => {
let testCollectionAddress: string;

before(async function () {
contract = new context.web3.eth.Contract(EVOLUTION_COLLETION_FACTORY_ABI, CONTRACT_ADDRESS, {
from: FAITH,
gasPrice: GAS_PRICE,
gas: GAS_LIMIT,
});
contract = new context.web3.eth.Contract(
EVOLUTION_COLLECTION_FACTORY_ABI,
EVOLUTION_COLLECTION_FACTORY_CONTRACT_ADDRESS,
{
from: FAITH,
gasPrice: GAS_PRICE,
gas: GAS_LIMIT,
}
);
context.web3.eth.accounts.wallet.add(FAITH_PRIVATE_KEY);
});

step("when collection is created, it should return owner", async function () {
const collectionContract = await createCollection(context);
testCollectionContract = collectionContract;

const owner = await collectionContract.methods.owner().call();
expect(owner).to.be.eq(FAITH);
});
Expand All @@ -55,9 +59,7 @@ describeWithExistingNode("Frontier RPC (Create Collection)", (context) => {
// event topics
expect(result.events.NewCollection.raw.topics.length).to.be.eq(2);
expect(result.events.NewCollection.raw.topics[0]).to.be.eq(SELECTOR_LOG_NEW_COLLECTION);
expect(result.events.NewCollection.raw.topics[1]).to.be.eq(
context.web3.utils.padLeft(FAITH.toLowerCase(), 64)
);
expect(result.events.NewCollection.raw.topics[1]).to.be.eq(context.web3.utils.padLeft(FAITH.toLowerCase(), 64));

// event data
expect(result.events.NewCollection.raw.data.toLowerCase()).to.be.eq(
Expand All @@ -79,14 +81,18 @@ describeWithExistingNode("Frontier RPC (Create Collection)", (context) => {
});

step("create collection call can estimate gas", async function () {
const contract = new context.web3.eth.Contract(EVOLUTION_COLLETION_FACTORY_ABI, CONTRACT_ADDRESS, {
from: FAITH,
gasPrice: GAS_PRICE,
});

const contract = new context.web3.eth.Contract(
EVOLUTION_COLLECTION_FACTORY_ABI,
EVOLUTION_COLLECTION_FACTORY_CONTRACT_ADDRESS,
{
from: FAITH,
gasPrice: GAS_PRICE,
}
);

let nonce = await context.web3.eth.getTransactionCount(FAITH);
context.web3.eth.accounts.wallet.add(FAITH_PRIVATE_KEY);

const estimatedGas = await contract.methods.createCollection(FAITH).estimateGas({
from: FAITH,
gas: GAS_LIMIT,
Expand Down
Loading
Loading