Skip to content

Commit

Permalink
Update Feat 2.0 branch (#291)
Browse files Browse the repository at this point in the history
* First compile

* Tests update

* Revert fork change for casper-fixtures

* Fixing the opcode-192 issue (#274)

* Thank You Rafal

* fix lint

* Update toolchains

* Update js-client package

---------

Co-authored-by: gRoussac <[email protected]>
# Conflicts:
#	client-js/package-lock.json
#	client-js/package.json

* #270 Back port fix from cep-18 + #267 nft_kind should be optional on install + default (#280)

* #270 Back port fix from cep-18
#267 nft_kind should be optional on install + default

* clippy

* Update doc

* Revert in get_optional_named_arg_with_user_errors

* Clippy

* Remove noImplicitUseStrict in client-js

* Client-js TS clean up

* Client-js update

* Temp Fix migrating test

* Update toolchain

* Set contract version to string in named_keys (major+minor)

* Small change

* Remove query_contract_value helper

* get_immediate_caller internal

* Rename make_dictionary_item_key

* Workspace

* Typo

* Update client

* Test CI/CD

* Syntax make

* Disable tests in CI/CD client-js

* Get protocol version from ffi

* Missing fields in Cargo.toml contract

* Small change contract_entity_key

* Use get_protocol_version

* Clean up utils
  • Loading branch information
gRoussac authored Feb 12, 2025
1 parent 0a24c97 commit c299d19
Show file tree
Hide file tree
Showing 89 changed files with 2,662 additions and 2,580 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target-dir = "target"
100 changes: 50 additions & 50 deletions .github/workflows/ci-cep-78-client.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
name: ci-casper-cep78-js-client
# name: ci-casper-cep78-js-client

on:
push:
branches:
- "dev"
- "feat-*"
- "release-*"
# on:
# push:
# branches:
# - "dev"
# - "feat-*"
# - "release-*"

pull_request:
branches:
- "dev"
- "feat-*"
- "release-*"
# pull_request:
# branches:
# - "dev"
# - "feat-*"
# - "release-*"

jobs:
client-build:
strategy:
fail-fast: false
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [18.x]
os: [ubuntu-20.04, ubuntu-22.04]
runs-on: ${{ matrix.os }}
# jobs:
# client-build:
# strategy:
# fail-fast: false
# matrix:
# # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
# node-version: [18.x]
# os: [ubuntu-20.04, ubuntu-22.04]
# runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2
# steps:
# - name: Checkout
# uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2

- uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c #v1.4.0
# - uses: Swatinem/rust-cache@cb2cf0cc7c5198d3364b9630e2c3d457f160790c #v1.4.0

- name: Install dependencies
run: sudo apt update && sudo apt install -y build-essential wabt
# - name: Install dependencies
# run: sudo apt update && sudo apt install -y build-essential wabt

- name: Setup
run: make prepare
# - name: Setup
# run: make prepare

- name: Prepare WASMs
run: make setup-test
# - name: Prepare WASMs
# run: make setup-test

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@5b949b50c3461bbcd5a540b150c368278160234a #v3.4.0
with:
node-version: ${{ matrix.node-version }}
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@5b949b50c3461bbcd5a540b150c368278160234a #v3.4.0
# with:
# node-version: ${{ matrix.node-version }}

- name: Install
working-directory: ./client-js
run: npm install
# - name: Install
# working-directory: ./client-js
# run: npm install

- name: Copy & convert WASMs
working-directory: ./client-js
run: npm run wasms:convert
# - name: Copy & convert WASMs
# working-directory: ./client-js
# run: npm run wasms:convert

- name: Audits
working-directory: ./client-js
run: npm audit --omit=dev
# - name: Audits
# working-directory: ./client-js
# run: npm audit --omit=dev

- name: Lints
working-directory: ./client-js
run: npm run lint
# - name: Lints
# working-directory: ./client-js
# run: npm run lint

- name: Test
working-directory: ./client-js
run: npm test
# - name: Test
# working-directory: ./client-js
# run: npm test
36 changes: 36 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[workspace]
members = [
"contracts/contract",
"contracts/client/balance_of_session",
"contracts/client/get_approved_session",
"contracts/client/is_approved_for_all_session",
"contracts/client/mint_session",
"contracts/client/owner_of_session",
"contracts/client/transfer_session",
"contracts/client/updated_receipts",
"contracts/test-contracts/mangle_named_keys",
"contracts/test-contracts/minting_contract",
"contracts/test-contracts/transfer_filter_contract",
"tests",
]
default-members = ["contracts/contract", "tests"]
resolver = "2"

[workspace.package]
version = "2.0.0"
edition = "2021"
description = "A library for developing CEP-78 tokens for the Casper network."
readme = "README.md"
documentation = "https://docs.rs/casper-cep78"
homepage = "https://github.com/casper-ecosystem"
repository = "https://github.com/casper-ecosystem/cep-78-enhanced-nft"
license-file = "LICENSE"

[workspace.dependencies]
casper-contract = { version = "4.0.0", git = "https://github.com/casper-network/casper-node.git", default-features = false }
casper-types = { version = "5.0.0", git = "https://github.com/casper-network/casper-node.git", default-features = false }
casper-event-standard = { git = "https://github.com/make-software/casper-event-standard", branch = "casper-2.0", default-features = false }

[profile.release]
codegen-units = 1
lto = true
155 changes: 58 additions & 97 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,125 +1,86 @@
PINNED_TOOLCHAIN := $(shell cat rust-toolchain)
# Variables
PINNED_TOOLCHAIN := $(shell cat contracts/rust-toolchain)
WASM_TARGET_DIR := ./target/wasm32-unknown-unknown/release
WASM_OUTPUT_DIR := tests/wasm
RUSTFLAGS := -C target-cpu=mvp
CARGO_BUILD_FLAGS := -Z build-std=std,panic_abort

# List of session and contract crates
SESSION_CRATES := balance_of_session get_approved_session is_approved_for_all_session \
mint_session owner_of_session transfer_session updated_receipts
CONTRACT_CRATES := mangle_named_keys minting_contract transfer_filter_contract
ALL_CRATES := cep78 $(SESSION_CRATES) $(CONTRACT_CRATES)
VERSIONS :=

# Helper macros
define build_and_strip
RUSTFLAGS="$(RUSTFLAGS)" cargo +$(PINNED_TOOLCHAIN) build --release --target wasm32-unknown-unknown $(CARGO_BUILD_FLAGS) -p $1 ;
wasm-strip $(WASM_TARGET_DIR)/$1.wasm ;
endef

# Targets
prepare:
rustup install $(PINNED_TOOLCHAIN)
rustup target add wasm32-unknown-unknown
rustup component add clippy --toolchain ${PINNED_TOOLCHAIN}
rustup component add rustfmt --toolchain ${PINNED_TOOLCHAIN}
rustup component add clippy --toolchain $(PINNED_TOOLCHAIN)
rustup component add rustfmt --toolchain $(PINNED_TOOLCHAIN)
rustup component add rust-src --toolchain $(PINNED_TOOLCHAIN)

.PHONY: build-contract
build-contract:
cd contract && cargo build --release --target wasm32-unknown-unknown
cd client/mint_session && cargo build --release --target wasm32-unknown-unknown
cd client/balance_of_session && cargo build --release --target wasm32-unknown-unknown
cd client/owner_of_session && cargo build --release --target wasm32-unknown-unknown
cd client/get_approved_session && cargo build --release --target wasm32-unknown-unknown
cd client/is_approved_for_all_session && cargo build --release --target wasm32-unknown-unknown
cd client/transfer_session && cargo build --release --target wasm32-unknown-unknown
cd client/updated_receipts && cargo build --release --target wasm32-unknown-unknown
cd test-contracts/minting_contract && cargo build --release --target wasm32-unknown-unknown
cd test-contracts/mangle_named_keys && cargo build --release --target wasm32-unknown-unknown
cd test-contracts/transfer_filter_contract && cargo build --release --target wasm32-unknown-unknown
wasm-strip contract/target/wasm32-unknown-unknown/release/contract.wasm
wasm-strip client/mint_session/target/wasm32-unknown-unknown/release/mint_call.wasm
wasm-strip client/balance_of_session/target/wasm32-unknown-unknown/release/balance_of_call.wasm
wasm-strip client/owner_of_session/target/wasm32-unknown-unknown/release/owner_of_call.wasm
wasm-strip client/get_approved_session/target/wasm32-unknown-unknown/release/get_approved_call.wasm
wasm-strip client/is_approved_for_all_session/target/wasm32-unknown-unknown/release/is_approved_for_all_call.wasm
wasm-strip client/transfer_session/target/wasm32-unknown-unknown/release/transfer_call.wasm
wasm-strip client/updated_receipts/target/wasm32-unknown-unknown/release/updated_receipts.wasm
wasm-strip test-contracts/minting_contract/target/wasm32-unknown-unknown/release/minting_contract.wasm
wasm-strip test-contracts/transfer_filter_contract/target/wasm32-unknown-unknown/release/transfer_filter_contract.wasm
$(call build_and_strip,cep78)

VERSIONS :=
.PHONY: build-all-contracts
build-all-contracts: build-contract
$(foreach crate, $(SESSION_CRATES), $(call build_and_strip,$(crate)))
$(foreach crate, $(CONTRACT_CRATES), $(call build_and_strip,$(crate)))

.PHONY: setup-test
setup-test: build-all-contracts
mkdir -p $(WASM_OUTPUT_DIR)

setup-test: build-contract
mkdir -p tests/wasm
$(foreach version,$(VERSIONS), \
if [ ! -d "tests/wasm/$(version)" ]; then \
mkdir -p tests/wasm/$(version); \
curl -L https://github.com/casper-ecosystem/cep-78-enhanced-nft/releases/download/v$(subst _,.,$(version))/cep-78-wasm.tar.gz | tar zxv -C tests/wasm/$(version)/; \
fi; \
)

cp contract/target/wasm32-unknown-unknown/release/contract.wasm tests/wasm
cp client/mint_session/target/wasm32-unknown-unknown/release/mint_call.wasm tests/wasm
cp client/balance_of_session/target/wasm32-unknown-unknown/release/balance_of_call.wasm tests/wasm
cp client/owner_of_session/target/wasm32-unknown-unknown/release/owner_of_call.wasm tests/wasm
cp client/get_approved_session/target/wasm32-unknown-unknown/release/get_approved_call.wasm tests/wasm
cp client/is_approved_for_all_session/target/wasm32-unknown-unknown/release/is_approved_for_all_call.wasm tests/wasm
cp client/transfer_session/target/wasm32-unknown-unknown/release/transfer_call.wasm tests/wasm
cp client/updated_receipts/target/wasm32-unknown-unknown/release/updated_receipts.wasm tests/wasm
cp test-contracts/minting_contract/target/wasm32-unknown-unknown/release/minting_contract.wasm tests/wasm
cp test-contracts/mangle_named_keys/target/wasm32-unknown-unknown/release/mangle_named_keys.wasm tests/wasm
cp test-contracts/transfer_filter_contract/target/wasm32-unknown-unknown/release/transfer_filter_contract.wasm tests/wasm
cp $(WASM_TARGET_DIR)/*.wasm $(WASM_OUTPUT_DIR)

.PHONY: test
test: setup-test
cd tests && cargo test
cargo test -p tests --lib

.PHONY: clippy
clippy:
cd contract && cargo clippy --target wasm32-unknown-unknown --bins -- -D warnings
cd contract && cargo clippy --no-default-features --lib -- -D warnings
cd client/mint_session && cargo clippy --release --target wasm32-unknown-unknown -- -D warnings
cd client/balance_of_session && cargo clippy --release --target wasm32-unknown-unknown -- -D warnings
cd client/owner_of_session && cargo clippy --release --target wasm32-unknown-unknown -- -D warnings
cd client/get_approved_session && cargo clippy --release --target wasm32-unknown-unknown -- -D warnings
cd client/transfer_session && cargo clippy --release --target wasm32-unknown-unknown -- -D warnings
cd client/updated_receipts && cargo clippy --release --target wasm32-unknown-unknown -- -D warnings
cd test-contracts/minting_contract && cargo clippy --release --target wasm32-unknown-unknown -- -D warnings
cd test-contracts/mangle_named_keys && cargo clippy --release --target wasm32-unknown-unknown -- -D warnings
cd test-contracts/transfer_filter_contract && cargo clippy --release --target wasm32-unknown-unknown -- -D warnings
cd tests && cargo clippy --all-targets -- -D warnings
cargo +$(PINNED_TOOLCHAIN) clippy --release -p cep78 --lib --target wasm32-unknown-unknown $(CARGO_BUILD_FLAGS) -- -D warnings
$(foreach crate, $(ALL_CRATES), \
cargo +$(PINNED_TOOLCHAIN) clippy --release -p $(crate) --bins --target wasm32-unknown-unknown $(CARGO_BUILD_FLAGS) -- -D warnings; \
)
cargo clippy --release -p tests --all-targets -- -D warnings

.PHONY: check-lint
check-lint: clippy
cd contract && cargo fmt -- --check
cd client/mint_session && cargo fmt -- --check
cd client/balance_of_session && cargo fmt -- --check
cd client/owner_of_session && cargo fmt -- --check
cd client/get_approved_session && cargo fmt -- --check
cd client/transfer_session && cargo fmt -- --check
cd client/updated_receipts && cargo fmt -- --check
cd test-contracts/minting_contract && cargo fmt -- --check
cd test-contracts/mangle_named_keys && cargo fmt -- --check
cd test-contracts/transfer_filter_contract && cargo fmt -- --check
cd tests && cargo fmt -- --check
$(foreach crate, $(ALL_CRATES), cargo +$(PINNED_TOOLCHAIN) fmt -p $(crate) -- --check;)
cargo fmt -p tests -- --check

lint: clippy fmt
.PHONY: lint
lint: clippy format

.PHONY: format
format:
cd contract && cargo fmt
cd client/mint_session && cargo fmt
cd client/balance_of_session && cargo fmt
cd client/owner_of_session && cargo fmt
cd client/get_approved_session && cargo fmt
cd client/transfer_session && cargo fmt
cd client/updated_receipts && cargo fmt
cd test-contracts/minting_contract && cargo fmt
cd test-contracts/mangle_named_keys && cargo fmt
cd test-contracts/transfer_filter_contract && cargo fmt
cd tests && cargo fmt
$(foreach crate, $(ALL_CRATES), cargo +$(PINNED_TOOLCHAIN) fmt -p $(crate);)
cargo fmt -p tests

.PHONY: clean
clean:
cd contract && cargo clean
cd client/mint_session && cargo clean
cd client/balance_of_session && cargo clean
cd client/owner_of_session && cargo clean
cd client/get_approved_session && cargo clean
cd client/transfer_session && cargo clean
cd client/updated_receipts && cargo clean
cd test-contracts/minting_contract && cargo clean
cd test-contracts/mangle_named_keys && cargo clean
cd test-contracts/transfer_filter_contract && cargo clean
cd tests && cargo clean
rm -rf tests/wasm
$(foreach crate, $(ALL_CRATES), cargo clean -p $(crate);)
cargo clean -p tests
rm -rf $(WASM_OUTPUT_DIR)
rm -rf ./*/Cargo.lock

.PHONY: cargo-update
cargo-update:
cd contract && cargo update
cd client/mint_session && cargo update
cd client/balance_of_session && cargo update
cd client/owner_of_session && cargo update
cd client/get_approved_session && cargo update
cd client/transfer_session && cargo update
cd client/updated_receipts && cargo update
cd test-contracts/minting_contract && cargo update
cd test-contracts/mangle_named_keys && cargo update
cd test-contracts/transfer_filter_contract && cargo update
cd tests && cargo update
$(foreach crate, $(ALL_CRATES), cargo update -p $(crate);)
cargo update -p tests
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ The following are the required runtime arguments that must be passed to the inst
- `"collection_symbol"`: The symbol representing a given NFT collection, passed in as a `String`. This parameter is required and cannot be changed post installation.
- `"total_token_supply"`: The total number of NFTs that a specific instance of a contract will mint passed in as a `U64` value. This parameter is required.
- `"ownership_mode"`: The [`OwnershipMode`](/docs/modalities.md#ownership) modality that dictates the ownership behavior of the NFT contract. This argument is passed in as a `u8` value and is required at the time of installation.
- `"nft_kind"`: The [`NFTKind`](/docs/modalities.md#nftkind) modality that specifies the off-chain items represented by the on-chain NFT data. This argument is passed in as a `u8` value and is required at the time of installation.
- `"json_schema"`: The JSON schema for the NFT tokens that will be minted by the NFT contract passed in as a `String`. This parameter is required if the metadata kind is set to `CustomValidated(3)` and cannot be changed post installation.
- `"nft_metadata_kind"`: The base metadata schema for the NFTs to be minted by the NFT contract. This argument is passed in as a `u8` value and is required at the time of installation.
- `"identifier_mode"`: The [`NFTIdentifierMode`](/docs/modalities.md#nftidentifiermode) modality dictates the primary identifier for NFTs minted by the contract. This argument is passed in as a `u8` value and is required at the time of installation.
Expand All @@ -58,7 +57,7 @@ The following are the optional parameters that can be passed in at the time of i

- `"minting_mode"`: The [`MintingMode`](/docs/modalities.md#minting) modality that dictates the access to the `mint()` entry-point in the NFT contract. This is an optional parameter that will default to restricting access to the installer of the contract. This parameter cannot be changed once the contract has been installed.
- `"allow_minting"`: The `"allow_minting"` flag allows the installer of the contract to pause the minting of new NFTs. The `allow_minting` is a boolean toggle that allows minting when `true`. If not provided at install the toggle will default to `true`. This value can be changed by the installer by calling the `set_variables()` entrypoint.

- `"nft_kind"`: The [`NFTKind`](/docs/modalities.md#nftkind) modality that specifies the off-chain items represented by the on-chain NFT data. This argument is passed in as a `u8` value and is optional at the time of installation. If not provided at install the toggle will default to `Virtual` This parameter cannot be changed once the contract has been installed.
- `"whitelist_mode"`: The [`WhitelistMode`](/docs/modalities.md#whitelistmode) modality dictates whether the contract whitelist can be updated. This optional parameter will default to an unlocked whitelist that can be updated post installation. This parameter cannot be changed once the contract has been installed.
- `"holder_mode"`: The [`NFTHolderMode`](/docs/modalities.md#nftholdermode) modality dictates which entities can hold NFTs. This is an optional parameter and will default to a mixed mode allowing either `Accounts` or `Contracts` to hold NFTs. This parameter cannot be changed once the contract has been installed.
- `"acl_whitelist"`: The ACL whitelist is a list of accounts and/or contract/package hashes that specifies which accounts and/or contracts can call the `mint()` entrypoint to mint NFTs. This is an optional parameter which will default to an empty whitelist. This value can be changed via the `set_variables` post installation. If the whitelist mode is set to locked, a non-empty whitelist must be passed; else, installation of the contract will fail.
Expand Down
5 changes: 3 additions & 2 deletions client-js/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
'prettier',
],
rules: {
"import/prefer-default-export": "off"
}
'import/prefer-default-export': 'off',
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
},
};
Loading

0 comments on commit c299d19

Please sign in to comment.