Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gianalarcon committed Jul 20, 2024
1 parent 21f5465 commit b9fd22c
Show file tree
Hide file tree
Showing 5 changed files with 330 additions and 53 deletions.
14 changes: 7 additions & 7 deletions packages/nextjs/app/token-vendor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ const TokenVendor: NextPage = () => {

const { data: vendorContractBalance } = useBalance({
address: vendorContractData?.address,
watch: true,
blockIdentifier: "pending" as BlockNumber, // to-do: Improve this
watch: true,
blockIdentifier: "pending" as BlockNumber, // to-do: Improve this
});

const { data: tokensPerEth } = useScaffoldReadContract({
contractName: "Vendor",
functionName: "tokens_per_eth",
});

// const { writeAsync: transferTokens } = useScaffoldWriteContract({
// contractName: "YourToken",
// functionName: "transfer",
// args: [toAddress, multiplyTo1e18(tokensToSend)],
// });
// const { writeAsync: transferTokens } = useScaffoldWriteContract({
// contractName: "YourToken",
// functionName: "transfer",
// args: [toAddress, multiplyTo1e18(tokensToSend)],
// });

const eth_to_spent = getTokenPrice(
tokensToBuy,
Expand Down
285 changes: 284 additions & 1 deletion packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const deployedContracts = {
devnet: {
YourToken: {
address:
"0x043c53b09fbfd4a921253cd5ba549904edc8ac5195597e58cad3aaaf91181dc2",
"0x07ad7a12a7671e2abc24681007cf0f2a36a0f5fb0f8867e4363c6612ebb52ce4",
abi: [
{
type: "impl",
Expand Down Expand Up @@ -307,6 +307,289 @@ const deployedContracts = {
},
],
},
Vendor: {
address:
"0x024a7d92cb64b9e4c2b59a38a616a5c2d3c12677e47abb04cb6205256bd5ed54",
abi: [
{
type: "impl",
name: "VendorImpl",
interface_name: "contracts::Vendor::IVendor",
},
{
type: "struct",
name: "core::integer::u256",
members: [
{
name: "low",
type: "core::integer::u128",
},
{
name: "high",
type: "core::integer::u128",
},
],
},
{
type: "interface",
name: "contracts::Vendor::IVendor",
items: [
{
type: "function",
name: "buy_tokens",
inputs: [
{
name: "eth_amount_wei",
type: "core::integer::u256",
},
],
outputs: [],
state_mutability: "external",
},
{
type: "function",
name: "withdraw",
inputs: [],
outputs: [],
state_mutability: "external",
},
{
type: "function",
name: "sell_tokens",
inputs: [
{
name: "amount_tokens",
type: "core::integer::u256",
},
],
outputs: [],
state_mutability: "external",
},
{
type: "function",
name: "send_tokens",
inputs: [
{
name: "to",
type: "core::starknet::contract_address::ContractAddress",
},
{
name: "amount_tokens",
type: "core::integer::u256",
},
],
outputs: [],
state_mutability: "external",
},
{
type: "function",
name: "tokens_per_eth",
inputs: [],
outputs: [
{
type: "core::integer::u256",
},
],
state_mutability: "view",
},
{
type: "function",
name: "your_token",
inputs: [],
outputs: [
{
type: "core::starknet::contract_address::ContractAddress",
},
],
state_mutability: "view",
},
{
type: "function",
name: "eth_token",
inputs: [],
outputs: [
{
type: "core::starknet::contract_address::ContractAddress",
},
],
state_mutability: "view",
},
],
},
{
type: "impl",
name: "OwnableImpl",
interface_name: "openzeppelin::access::ownable::interface::IOwnable",
},
{
type: "interface",
name: "openzeppelin::access::ownable::interface::IOwnable",
items: [
{
type: "function",
name: "owner",
inputs: [],
outputs: [
{
type: "core::starknet::contract_address::ContractAddress",
},
],
state_mutability: "view",
},
{
type: "function",
name: "transfer_ownership",
inputs: [
{
name: "new_owner",
type: "core::starknet::contract_address::ContractAddress",
},
],
outputs: [],
state_mutability: "external",
},
{
type: "function",
name: "renounce_ownership",
inputs: [],
outputs: [],
state_mutability: "external",
},
],
},
{
type: "constructor",
name: "constructor",
inputs: [
{
name: "eth_token_address",
type: "core::starknet::contract_address::ContractAddress",
},
{
name: "your_token_address",
type: "core::starknet::contract_address::ContractAddress",
},
],
},
{
type: "event",
name: "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferred",
kind: "struct",
members: [
{
name: "previous_owner",
type: "core::starknet::contract_address::ContractAddress",
kind: "key",
},
{
name: "new_owner",
type: "core::starknet::contract_address::ContractAddress",
kind: "key",
},
],
},
{
type: "event",
name: "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferStarted",
kind: "struct",
members: [
{
name: "previous_owner",
type: "core::starknet::contract_address::ContractAddress",
kind: "key",
},
{
name: "new_owner",
type: "core::starknet::contract_address::ContractAddress",
kind: "key",
},
],
},
{
type: "event",
name: "openzeppelin::access::ownable::ownable::OwnableComponent::Event",
kind: "enum",
variants: [
{
name: "OwnershipTransferred",
type: "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferred",
kind: "nested",
},
{
name: "OwnershipTransferStarted",
type: "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferStarted",
kind: "nested",
},
],
},
{
type: "event",
name: "contracts::Vendor::Vendor::BuyTokens",
kind: "struct",
members: [
{
name: "buyer",
type: "core::starknet::contract_address::ContractAddress",
kind: "data",
},
{
name: "eth_amount",
type: "core::integer::u256",
kind: "data",
},
{
name: "tokens_amount",
type: "core::integer::u256",
kind: "data",
},
],
},
{
type: "event",
name: "contracts::Vendor::Vendor::SellTokens",
kind: "struct",
members: [
{
name: "seller",
type: "core::starknet::contract_address::ContractAddress",
kind: "key",
},
{
name: "tokens_amount",
type: "core::integer::u256",
kind: "data",
},
{
name: "eth_amount",
type: "core::integer::u256",
kind: "data",
},
],
},
{
type: "event",
name: "contracts::Vendor::Vendor::Event",
kind: "enum",
variants: [
{
name: "OwnableEvent",
type: "openzeppelin::access::ownable::ownable::OwnableComponent::Event",
kind: "flat",
},
{
name: "BuyTokens",
type: "contracts::Vendor::Vendor::BuyTokens",
kind: "nested",
},
{
name: "SellTokens",
type: "contracts::Vendor::Vendor::SellTokens",
kind: "nested",
},
],
},
],
},
},
sepolia: {
YourCollectible: {
Expand Down
2 changes: 1 addition & 1 deletion packages/snfoundry/contracts/src/Vendor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ mod Vendor {

fn tokens_per_eth(
self: @ContractState
) -> u256 { // Modify the return value to return the amount of tokens per 1 ETH.
) -> u256 { // Modify to return the amount of tokens per 1 ETH.
0
}

Expand Down
6 changes: 0 additions & 6 deletions packages/snfoundry/contracts/src/test/TestContract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ fn deploy_mock_eth_token() -> ContractAddress {
// Should deploy the YourToken contract
fn deploy_your_token_token() -> ContractAddress {
let erc20_class_hash = declare("YourToken").unwrap();
let NAME: ByteArray = "Gold";
let SYMBOL: ByteArray = "GLD";
let INITIAL_SUPPLY: u256 = 2000000000000000000000; // 2000_GLD_IN_WEI
let mut calldata = array![];
calldata.append_serde(NAME);
calldata.append_serde(SYMBOL);
calldata.append_serde(INITIAL_SUPPLY);
calldata.append_serde(RECIPIENT());
let (your_token_address, _) = erc20_class_hash.deploy(@calldata).unwrap();
println!("-- YourToken contract deployed on: {:?}", your_token_address);
Expand Down
Loading

0 comments on commit b9fd22c

Please sign in to comment.