Skip to content

Commit

Permalink
Merge pull request #15 from polymorpher/polymorpher/e2e-test
Browse files Browse the repository at this point in the history
Some basic test for publishing to Uniswap end-to-end. More verification logic needed
  • Loading branch information
potvik authored Dec 9, 2024
2 parents 32cf346 + 0c0f7e4 commit 07ae327
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 3 deletions.
24 changes: 21 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
# MAX_WEIGHT = 1000000;

# N=0.5
#WEIGHT_SCALED=666666
WEIGHT_SCALED=666666

# N=1
WEIGHT_SCALED=500000
#WEIGHT_SCALED=500000

# N=1.5
#WEIGHT_SCALED=400000
Expand Down Expand Up @@ -42,4 +42,22 @@ SLOPE_SCALED=20000
#SLOPE_SCALED=1000000

NUM_INCREMENTS=5
MINT_AMOUNT=100000
MINT_AMOUNT=100000

### For testing

INFURA_KEY=

## harmony

UNISWAP_V3_FACTORY=0x12d21f5d0Ab768c312E19653Bf3f89917866B8e8
UNISWAP_V3_NPM=0xE4E259BE9c84260FDC7C9a3629A0410b1Fb3C114
WETH=0xcF664087a5bB0237a0BAd6742852ec6c8d69A27a
FEE_PERCENT=50

## eth

#UNISWAP_V3_FACTORY=0x1F98431c8aD98523631AE4a59f267346ea31F984
#UNISWAP_V3_NPM=0xC36442b4a4522E871399CD717aBDD847Ab11FE88
#WETH=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
#FEE_PERCENT=50
7 changes: 7 additions & 0 deletions anvil.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/zsh

export $(grep -v '^#' .env | xargs)

anvil -f https://a.api.s0.t.hmny.io/ --fork-block-number 66513894

#anvil -f https://mainnet.infura.io/v3/${INFURA_KEY} --fork-block-number 20488727
4 changes: 4 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/zsh

export $(grep -v '^#' .env | xargs)
forge test -vv --match-test test_publishToUniswap -f http://127.0.0.1:8545
102 changes: 102 additions & 0 deletions test/E2E.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
pragma solidity >=0.8.26;

import "forge-std/Test.sol";
import "@contracts/TokenFactory.sol";
import "@contracts/BancorBondingCurve.sol";
import "@contracts/Token.sol";

contract E2ETest is Test {
TokenFactory internal tf;
BancorBondingCurve internal bc;
uint256 internal FEE_PERCENT = vm.envUint("FEE_PERCENT");
uint256 internal SLOPE_SCALED = vm.envUint("SLOPE_SCALED");
uint32 internal WEIGHT_SCALED = uint32(vm.envUint("WEIGHT_SCALED"));
address internal UNISWAP_V3_FACTORY = vm.envAddress("UNISWAP_V3_FACTORY");
address internal UNISWAP_V3_NPM = vm.envAddress("UNISWAP_V3_NPM");
address internal WETH = vm.envAddress("WETH");
Token internal ta;
Token internal tb;
Token internal tc;

address Owner = address(0x1234);
address Alice = address(0x1235);
address Bob = address(0x1236);
address Charlie = address(0x1237);
address Dave = address(0x1238);
address Server = address(0x1239);

function setUp() public {
vm.deal(Alice, 100 ether);
vm.deal(Bob, 100 ether);
vm.deal(Charlie, 100 ether);
vm.deal(Dave, 1 ether);
Token tref = new Token();
vm.startPrank(Owner);
vm.deal(Owner, 1000 ether);
bc = new BancorBondingCurve(SLOPE_SCALED, WEIGHT_SCALED);
tf = new TokenFactory(address(tref), UNISWAP_V3_FACTORY, UNISWAP_V3_NPM, address(bc), WETH, FEE_PERCENT);
vm.stopPrank();

vm.startPrank(Alice);
ta = tf.createToken("a", "A", "https://a.local");
tf.buy{value: 1 ether}(address(ta));
vm.stopPrank();

vm.startPrank(Bob);
tb = tf.createToken("b", "B", "https://b.local");
tf.buy{value: 1 ether}(address(tb));
vm.stopPrank();

vm.startPrank(Charlie);
tc = tf.createToken("c", "C", "https://c.local");
tf.buy{value: 1 ether}(address(tc));
vm.stopPrank();

}

function test_publishToUniswap() public {
vm.startPrank(Dave);
tf.buy{value: 0.1 ether}(address(ta));
// TODO: check price, token balance, ... after each buy
tf.buy{value: 0.1 ether}(address(ta));
tf.buy{value: 0.05 ether}(address(tb));
tf.buy{value: 0.02 ether}(address(tc));
vm.stopPrank();

vm.startPrank(Owner);
tf.startNewCompetition();
// TODO: check fee, test withdraw fee
vm.stopPrank();

vm.startPrank(Server);
vm.expectRevert();
tf.publishToUniswap(address(tb));
vm.expectRevert();
tf.publishToUniswap(address(tc));
// TODO: check event emission, token minting amount...
tf.publishToUniswap(address(ta));
vm.stopPrank();
// TODO: check uniswap pool liquidity and price

vm.startPrank(Bob);
tf.burnTokenAndMintWinner(address(tb));
// TODO: check event emission, token minting amount...
vm.stopPrank();

vm.startPrank(Charlie);
tf.burnTokenAndMintWinner(address(tc));
// TODO: check event emission, token minting amount...
vm.stopPrank();

vm.startPrank(Dave);
tf.burnTokenAndMintWinner(address(tb));
// TODO: check event emission, token minting amount...
tf.burnTokenAndMintWinner(address(tc));
// TODO: check event emission, token minting amount...
vm.stopPrank();

// TODO: have alice to trade some tokens on uniswap

// TODO: have bob / charlie / dave to trade token ta on uniswap
}
}

0 comments on commit 07ae327

Please sign in to comment.