Skip to content

Commit

Permalink
♻️ refactor integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bal7hazar committed Aug 25, 2022
1 parent 0761275 commit d13519e
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 182 deletions.
27 changes: 27 additions & 0 deletions tests/integrations/minter/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
user:
admin: 1000
anyone: 1001

nft:
name: Project
symbol: NFT

token:
name: Token
symbol: TOK
decimals: 6
initial_supply: 1000000

minter:
public_sale_open: 0
max_buy_per_tx: 5
unit_price: 10
max_supply_for_mint: 10
reserved_supply_for_mint: 4

whitelist:
slots: 5
merkle_root: 3236969588476960619958150604131083087415975923122021901088942336874683133579
merkle_proof:
- 1489335374474017495857579265074565262713421005832572026644103123081435719307
merkle_proof_len: 1
100 changes: 35 additions & 65 deletions tests/integrations/minter/library.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,96 +17,66 @@ from openzeppelin.security.safemath import SafeUint256
from interfaces.minter import ICarbonableMinter
from interfaces.CarbonableProjectNFT import IERC721, IERC721_Enumerable, ICarbonableProjectNFT

func setup{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
admin_address : felt,
anyone_address : felt,
nft_name : felt,
nft_symbol : felt,
token_name : felt,
token_symbol : felt,
token_decimals : felt,
token_initial_supply : felt,
minter_public_sale_open : felt,
minter_max_buy_per_tx : felt,
minter_unit_price : felt,
minter_max_supply_for_mint : felt,
minter_reserved_supply_for_mint : felt,
whitelist_slots : felt,
whitelist_merkle_root : felt,
whitelist_merkle_proof : felt*,
whitelist_merkle_proof_len : felt,
):
func setup{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}():
alloc_locals
tempvar carbonable_minter
local carbonable_minter
local merkle_root
%{
# --- INITIAL SETTINGS ---
# User addresses
context.ADMIN = ids.admin_address
context.ANYONE = ids.anyone_address
# CarbonableProjectNFT
context.NFT_NAME = ids.nft_name
context.NFT_SYMBOL = ids.nft_symbol
# Payment token
context.TOKEN_NAME = ids.token_name
context.TOKEN_SYMBOL = ids.token_symbol
context.TOKEN_DECIMALS = ids.token_decimals
context.TOKEN_INITIAL_SUPPLY = ids.token_initial_supply
# CarbonableMint
context.PUBLIC_SALE_OPEN = ids.minter_public_sale_open
context.MAX_BUY_PER_TX = ids.minter_max_buy_per_tx
context.UNIT_PRICE = ids.minter_unit_price
context.MAX_SUPPLY_FOR_MINT = ids.minter_max_supply_for_mint
context.RESERVED_SUPPLY_FOR_MINT = ids.minter_reserved_supply_for_mint
# Whitelist ANYONE
context.SLOTS = ids.whitelist_slots
context.PROOF_LEN = ids.whitelist_merkle_proof_len
context.PROOF = [
memory[ids.whitelist_merkle_proof + index]
for index in range(context.PROOF_LEN)
]
# Load config
import yaml
with open("./tests/integrations/minter/config.yml", 'r') as file_instance:
config = yaml.safe_load(file_instance)
for section, subconfig in config.items():
for key, value in subconfig.items():
name = f"{section.lower()}_{key.lower()}"
setattr(context, name, value)
# ERC-721 deployment
context.project_nft_contract = deploy_contract(
"./src/nft/project/CarbonableProjectNFT.cairo",
{
"name": context.NFT_NAME,
"symbol": context.NFT_SYMBOL,
"owner": context.ADMIN,
"name": context.nft_name,
"symbol": context.nft_symbol,
"owner": context.user_admin,
},
).contract_address
# ERC-20 deployment
context.payment_token_contract = deploy_contract(
"./tests/mocks/token/erc20.cairo",
{
"name": context.TOKEN_NAME,
"symbol": context.TOKEN_SYMBOL,
"decimals": context.TOKEN_DECIMALS,
"initial_supply": context.TOKEN_INITIAL_SUPPLY,
"recipient": context.ANYONE
"name": context.token_name,
"symbol": context.token_symbol,
"decimals": context.token_decimals,
"initial_supply": context.token_initial_supply,
"recipient": context.user_anyone
},
).contract_address
# Minter deployment
context.carbonable_minter_contract = deploy_contract(
"./src/mint/minter.cairo",
{
"owner": context.ADMIN,
"owner": context.user_admin,
"project_nft_address": context.project_nft_contract,
"payment_token_address": context.payment_token_contract,
"public_sale_open": context.PUBLIC_SALE_OPEN,
"max_buy_per_tx": context.MAX_BUY_PER_TX,
"unit_price": context.UNIT_PRICE,
"max_supply_for_mint": context.MAX_SUPPLY_FOR_MINT,
"reserved_supply_for_mint": context.RESERVED_SUPPLY_FOR_MINT,
"public_sale_open": context.minter_public_sale_open,
"max_buy_per_tx": context.minter_max_buy_per_tx,
"unit_price": context.minter_unit_price,
"max_supply_for_mint": context.minter_max_supply_for_mint,
"reserved_supply_for_mint": context.minter_reserved_supply_for_mint,
},
).contract_address
# Externalize required variables
ids.carbonable_minter = context.carbonable_minter_contract
ids.merkle_root = context.whitelist_merkle_root
%}

# Transfer project nft ownershop from admin to minter
admin_instance.transferOwnership(carbonable_minter)
admin_instance.set_whitelist_merkle_root(whitelist_merkle_root)
# Set merkle tree root to minter contract
admin_instance.set_whitelist_merkle_root(merkle_root)

return ()
end
Expand Down Expand Up @@ -370,7 +340,7 @@ namespace admin_instance:

func get_address() -> (address : felt):
tempvar admin
%{ ids.admin = context.ADMIN %}
%{ ids.admin = context.user_admin %}
return (admin)
end

Expand Down Expand Up @@ -538,27 +508,27 @@ namespace anyone_instance:

func get_address() -> (address : felt):
tempvar anyone
%{ ids.anyone = context.ANYONE %}
%{ ids.anyone = context.user_anyone %}
return (anyone)
end

func get_slots() -> (slots : felt):
tempvar slots
%{ ids.slots = context.SLOTS %}
%{ ids.slots = context.whitelist_slots %}
return (slots)
end

func get_proof_len() -> (proof_len : felt):
tempvar proof_len
%{ ids.proof_len = context.PROOF_LEN %}
%{ ids.proof_len = context.whitelist_merkle_proof_len %}
return (proof_len)
end

func get_proof() -> (proof : felt*):
alloc_locals
let (local proof : felt*) = alloc()
%{
for index, node in enumerate(context.PROOF):
for index, node in enumerate(context.whitelist_merkle_proof):
memory[ids.proof + index] = node
%}
return (proof)
Expand Down
30 changes: 1 addition & 29 deletions tests/integrations/minter/test_nominal_cases.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
%lang starknet

# Starkware dependencies
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.bool import TRUE, FALSE
from starkware.cairo.common.cairo_builtins import HashBuiltin

Expand All @@ -17,34 +16,7 @@ from tests.integrations.minter.library import (

@view
func __setup__{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}():
alloc_locals
let (local whitelist_merkle_proof : felt*) = alloc()
assert [whitelist_merkle_proof] = 1489335374474017495857579265074565262713421005832572026644103123081435719307
let whitelist_merkle_proof_len = 1
setup(
# User addresses
admin_address=1000,
anyone_address=1001,
# CarbonableProjectNFT
nft_name='Carbonable ERC-721 Test',
nft_symbol='CET',
# Payment token
token_name='StableCoinToken',
token_symbol='SCT',
token_decimals=6,
token_initial_supply=1000000,
# CarbonableMint
minter_public_sale_open=FALSE,
minter_max_buy_per_tx=5,
minter_unit_price=10,
minter_max_supply_for_mint=10,
minter_reserved_supply_for_mint=4,
# Whitelist ANYONE
whitelist_slots=5,
whitelist_merkle_root=3236969588476960619958150604131083087415975923122021901088942336874683133579,
whitelist_merkle_proof=whitelist_merkle_proof,
whitelist_merkle_proof_len=whitelist_merkle_proof_len,
)
setup()
return ()
end

Expand Down
17 changes: 0 additions & 17 deletions tests/integrations/minter/test_specific_cases.cairo

This file was deleted.

19 changes: 19 additions & 0 deletions tests/integrations/yield/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
user:
admin: 1000
anyone: 1001

nft:
name: Project
symbol: NFT

token:
name: Token
symbol: TOK
decimals: 6
initial_supply: 1000000

carbonable_token:
name: Carbonable
symbol: CARBZ
decimals: 6
initial_supply: 1000000
68 changes: 68 additions & 0 deletions tests/integrations/yield/library.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# SPDX-License-Identifier: MIT
# Carbonable smart contracts written in Cairo v0.1.0 (library.cairo)

%lang starknet

# Starkware dependencies
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.bool import TRUE, FALSE

func setup{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}():
%{
# Load config
import yaml
with open("./tests/integrations/yield/config.yml", 'r') as file_instance:
config = yaml.safe_load(file_instance)
for section, subconfig in config.items():
for key, value in subconfig.items():
name = f"{section.lower()}_{key.lower()}"
setattr(context, name, value)
# ERC-721 deployment
context.project_nft_contract = deploy_contract(
"./src/nft/project/CarbonableProjectNFT.cairo",
{
"name": context.nft_name,
"symbol": context.nft_symbol,
"owner": context.user_admin,
},
).contract_address
# Reward token ERC-20 deployment
context.reward_token_contract = deploy_contract(
"./tests/mocks/token/erc20.cairo",
{
"name": context.token_name,
"symbol": context.token_symbol,
"decimals": context.token_decimals,
"initial_supply": context.token_initial_supply,
"recipient": context.user_anyone
},
).contract_address
# Carbonable token ERC-20 deployment
context.carbonable_token_contract = deploy_contract(
"./tests/mocks/token/erc20.cairo",
{
"name": context.carbonable_token_name,
"symbol": context.carbonable_token_symbol,
"decimals": context.carbonable_token_decimals,
"initial_supply": context.carbonable_token_initial_supply,
"recipient": context.user_anyone
},
).contract_address
# Yield Manager deployment
context.yield_manager_contract = deploy_contract(
"./src/yield/yield_manager.cairo",
{
"owner": context.user_admin,
"project_nft_address": context.project_nft_contract,
"carbonable_token_address": context.carbonable_token_contract,
"reward_token_address": context.reward_token_contract,
},
).contract_address
%}

return ()
end
Loading

0 comments on commit d13519e

Please sign in to comment.