Skip to content

Commit

Permalink
dex/{networks,testing}: Add simnet USDC
Browse files Browse the repository at this point in the history
This adds the usdc.eth and usdc.polygon assets to simnet and gets rid of
dextt.
  • Loading branch information
martonp committed Mar 24, 2024
1 parent 01ab269 commit dccd2ec
Show file tree
Hide file tree
Showing 31 changed files with 256 additions and 354 deletions.
2 changes: 1 addition & 1 deletion client/asset/eth/chaincfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NetworkCompatibilityData(net dex.Network) (c CompatibilityData, err error)
var (
tTxHashFile = filepath.Join(tDir, "test_tx_hash.txt")
tBlockHashFile = filepath.Join(tDir, "test_block10_hash.txt")
tContractFile = filepath.Join(tDir, "test_token_contract_address.txt")
tContractFile = filepath.Join(tDir, "test_usdc_contract_address.txt")
)
readIt := func(path string) string {
b, err := os.ReadFile(path)
Expand Down
2 changes: 1 addition & 1 deletion client/asset/eth/cmd/getgas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ The credentials file should have the JSON format in the example below. The seed
**example usage**
```
go build -tags lgpl
./getgas --simnet --n 3 --token dextt.eth
./getgas --simnet --n 3 --token usdc.eth
```
7 changes: 2 additions & 5 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ func registerToken(tokenID uint32, desc string) {

func init() {
asset.Register(BipID, &Driver{})
// Test token
registerToken(simnetTokenID, "A token wallet for the DEX test token. Used for testing DEX software.")
registerToken(usdcTokenID, "The USDC Ethereum ERC20 token.")
}

Expand Down Expand Up @@ -107,8 +105,7 @@ const (
)

var (
simnetTokenID, _ = dex.BipSymbolID("dextt.eth")
usdcTokenID, _ = dex.BipSymbolID("usdc.eth")
usdcTokenID, _ = dex.BipSymbolID("usdc.eth")
// blockTicker is the delay between calls to check for new blocks.
blockTicker = time.Second
peerCountTicker = 5 * time.Second
Expand Down Expand Up @@ -5430,7 +5427,7 @@ func (getGas) Estimate(ctx context.Context, net dex.Network, assetID, contractVe

// Run the miner now, in case we need it for the approval client preload.
if net == dex.Simnet {
symbolParts := strings.Split(symbol, ".") // e.g. dextt.polygon, dextt.eth
symbolParts := strings.Split(symbol, ".") // e.g. usdc.polygon, usdc.eth
runSimnetMiner(ctx, symbolParts[len(symbolParts)-1], log)
}

Expand Down
90 changes: 45 additions & 45 deletions client/asset/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
testAddressC = common.HexToAddress("2b84C791b79Ee37De042AD2ffF1A253c3ce9bc27")

ethGases = dexeth.VersionedGases[0]
tokenGases = dexeth.Tokens[simnetTokenID].NetTokens[dex.Simnet].SwapContracts[0].Gas
tokenGases = dexeth.Tokens[usdcTokenID].NetTokens[dex.Simnet].SwapContracts[0].Gas

tETH = &dex.Asset{
// Version meaning?
Expand All @@ -69,8 +69,8 @@ var (
}

tToken = &dex.Asset{
ID: simnetTokenID,
Symbol: "dextt.eth",
ID: usdcTokenID,
Symbol: "usdc.eth",
Version: 0,
SwapSize: tokenGases.Swap,
SwapSizeBase: tokenGases.Swap,
Expand Down Expand Up @@ -937,12 +937,12 @@ func tassetWallet(assetID uint32) (asset.Wallet, *assetWallet, *tMempoolNode, co
assetWallet: aw,
cfg: &tokenWalletConfig{},
parent: node.tokenParent,
token: dexeth.Tokens[simnetTokenID],
netToken: dexeth.Tokens[simnetTokenID].NetTokens[dex.Simnet],
token: dexeth.Tokens[usdcTokenID],
netToken: dexeth.Tokens[usdcTokenID].NetTokens[dex.Simnet],
}
aw.wallets = map[uint32]*assetWallet{
simnetTokenID: aw,
BipID: node.tokenParent,
usdcTokenID: aw,
BipID: node.tokenParent,
}
}

Expand Down Expand Up @@ -1036,7 +1036,7 @@ func TestBalanceWithMempool(t *testing.T) {
for _, test := range tests {
var assetID uint32 = BipID
if test.token {
assetID = simnetTokenID
assetID = usdcTokenID
}

_, eth, node, shutdown := tassetWallet(assetID)
Expand Down Expand Up @@ -1167,26 +1167,26 @@ func TestBalanceNoMempool(t *testing.T) {
name: "eth with token fees",
assetID: BipID,
unconfirmedTxs: map[uint64]*tExtendedWalletTx{
0: newExtendedWalletTx(simnetTokenID, 4, 5, 0, 0, asset.Send),
0: newExtendedWalletTx(usdcTokenID, 4, 5, 0, 0, asset.Send),
},
expPendingOut: 5,
expCountAfter: 1,
},
{
name: "token with 1 tx and other ignored assets",
assetID: simnetTokenID,
assetID: usdcTokenID,
unconfirmedTxs: map[uint64]*tExtendedWalletTx{
0: newExtendedWalletTx(simnetTokenID, 4, 5, 0, 0, asset.Send),
1: newExtendedWalletTx(simnetTokenID+1, 8, 9, 0, 0, asset.Send),
0: newExtendedWalletTx(usdcTokenID, 4, 5, 0, 0, asset.Send),
1: newExtendedWalletTx(usdcTokenID+1, 8, 9, 0, 0, asset.Send),
},
expPendingOut: 4,
expCountAfter: 2,
},
{
name: "token with 1 tx incoming",
assetID: simnetTokenID,
assetID: usdcTokenID,
unconfirmedTxs: map[uint64]*tExtendedWalletTx{
0: newExtendedWalletTx(simnetTokenID, 15, 5, 0, 0, asset.Redeem),
0: newExtendedWalletTx(usdcTokenID, 15, 5, 0, 0, asset.Redeem),
},
expPendingIn: 15,
expCountAfter: 1,
Expand All @@ -1195,20 +1195,20 @@ func TestBalanceNoMempool(t *testing.T) {
name: "eth mixed txs",
assetID: BipID,
unconfirmedTxs: map[uint64]*tExtendedWalletTx{
0: newExtendedWalletTx(BipID, 1, 2, 0, 0, asset.Swap), // 3 eth out
1: newExtendedWalletTx(simnetTokenID, 3, 4, 0, txConfsNeededToConfirm, asset.Send), // confirmed
2: newExtendedWalletTx(simnetTokenID, 5, 6, 0, 0, asset.Swap), // 6 eth out
3: newExtendedWalletTx(BipID, 7, 1, 0, 0, asset.Refund), // 1 eth out, 7 eth in
0: newExtendedWalletTx(BipID, 1, 2, 0, 0, asset.Swap), // 3 eth out
1: newExtendedWalletTx(usdcTokenID, 3, 4, 0, txConfsNeededToConfirm, asset.Send), // confirmed
2: newExtendedWalletTx(usdcTokenID, 5, 6, 0, 0, asset.Swap), // 6 eth out
3: newExtendedWalletTx(BipID, 7, 1, 0, 0, asset.Refund), // 1 eth out, 7 eth in
},
expPendingOut: 10,
expPendingIn: 7,
expCountAfter: 3,
},
{
name: "already confirmed, but still waiting for txConfsNeededToConfirm",
assetID: simnetTokenID,
assetID: usdcTokenID,
unconfirmedTxs: map[uint64]*tExtendedWalletTx{
0: newExtendedWalletTx(simnetTokenID, 15, 5, tipHeight, 1, asset.Redeem),
0: newExtendedWalletTx(usdcTokenID, 15, 5, tipHeight, 1, asset.Redeem),
},
expCountAfter: 1,
},
Expand Down Expand Up @@ -1313,7 +1313,7 @@ func TestFeeRate(t *testing.T) {

func TestRefund(t *testing.T) {
t.Run("eth", func(t *testing.T) { testRefund(t, BipID) })
t.Run("token", func(t *testing.T) { testRefund(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testRefund(t, usdcTokenID) })
}

func testRefund(t *testing.T, assetID uint32) {
Expand All @@ -1335,7 +1335,7 @@ func testRefund(t *testing.T, assetID uint32) {
if assetID == BipID {
eth.versionedGases[1] = gasesV1
} else {
eth.versionedGases[1] = &dexeth.Tokens[simnetTokenID].NetTokens[dex.Simnet].SwapContracts[0].Gas
eth.versionedGases[1] = &dexeth.Tokens[usdcTokenID].NetTokens[dex.Simnet].SwapContracts[0].Gas
v1c = &tTokenContractor{tContractor: v1Contractor}
}

Expand Down Expand Up @@ -1494,7 +1494,7 @@ func (b *badCoin) Value() uint64 {

func TestFundOrderReturnCoinsFundingCoins(t *testing.T) {
t.Run("eth", func(t *testing.T) { testFundOrderReturnCoinsFundingCoins(t, BipID) })
t.Run("token", func(t *testing.T) { testFundOrderReturnCoinsFundingCoins(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testFundOrderReturnCoinsFundingCoins(t, usdcTokenID) })
}

func testFundOrderReturnCoinsFundingCoins(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -1788,7 +1788,7 @@ func testFundOrderReturnCoinsFundingCoins(t *testing.T, assetID uint32) {

func TestFundMultiOrder(t *testing.T) {
t.Run("eth", func(t *testing.T) { testFundMultiOrder(t, BipID) })
t.Run("token", func(t *testing.T) { testFundMultiOrder(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testFundMultiOrder(t, usdcTokenID) })
}

func testFundMultiOrder(t *testing.T, assetID uint32) {
Expand All @@ -1801,7 +1801,7 @@ func testFundMultiOrder(t *testing.T, assetID uint32) {
if assetID != BipID {
fromAsset = tToken
node.tokenContractor.allow = unlimitedAllowance
swapGas = dexeth.Tokens[simnetTokenID].NetTokens[dex.Simnet].
swapGas = dexeth.Tokens[usdcTokenID].NetTokens[dex.Simnet].
SwapContracts[fromAsset.Version].Gas.Swap
}

Expand Down Expand Up @@ -2178,7 +2178,7 @@ func TestPreSwap(t *testing.T) {
var assetID uint32 = BipID
assetCfg := tETH
if test.token {
assetID = simnetTokenID
assetID = usdcTokenID
assetCfg = tToken
}

Expand Down Expand Up @@ -2244,7 +2244,7 @@ func TestPreSwap(t *testing.T) {

func TestSwap(t *testing.T) {
t.Run("eth", func(t *testing.T) { testSwap(t, BipID) })
t.Run("token", func(t *testing.T) { testSwap(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testSwap(t, usdcTokenID) })
}

func testSwap(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -2522,7 +2522,7 @@ func TestPreRedeem(t *testing.T) {
}

// Token
w, _, _, shutdown2 := tassetWallet(simnetTokenID)
w, _, _, shutdown2 := tassetWallet(usdcTokenID)
defer shutdown2()

form.Version = tToken.Version
Expand All @@ -2539,7 +2539,7 @@ func TestPreRedeem(t *testing.T) {

func TestRedeem(t *testing.T) {
t.Run("eth", func(t *testing.T) { testRedeem(t, BipID) })
t.Run("token", func(t *testing.T) { testRedeem(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testRedeem(t, usdcTokenID) })
}

func testRedeem(t *testing.T, assetID uint32) {
Expand All @@ -2554,7 +2554,7 @@ func testRedeem(t *testing.T, assetID uint32) {
eth.versionedGases[1] = &tokenGases
}

tokenContracts := eth.tokens[simnetTokenID].NetTokens[dex.Simnet].SwapContracts
tokenContracts := eth.tokens[usdcTokenID].NetTokens[dex.Simnet].SwapContracts
tokenContracts[1] = tokenContracts[0]
defer delete(tokenContracts, 1)

Expand Down Expand Up @@ -3234,7 +3234,7 @@ func TestMaxOrder(t *testing.T) {
var assetID uint32 = BipID
assetCfg := tETH
if test.token {
assetID = simnetTokenID
assetID = usdcTokenID
assetCfg = tToken
}

Expand Down Expand Up @@ -3330,7 +3330,7 @@ func packRedeemDataV0(redemptions []*dexeth.Redemption) ([]byte, error) {

func TestAuditContract(t *testing.T) {
t.Run("eth", func(t *testing.T) { testAuditContract(t, BipID) })
t.Run("token", func(t *testing.T) { testAuditContract(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testAuditContract(t, usdcTokenID) })
}

func testAuditContract(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -3916,7 +3916,7 @@ func TestLocktimeExpired(t *testing.T) {

func TestFindRedemption(t *testing.T) {
t.Run("eth", func(t *testing.T) { testFindRedemption(t, BipID) })
t.Run("token", func(t *testing.T) { testFindRedemption(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testFindRedemption(t, usdcTokenID) })
}

func testFindRedemption(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -4058,7 +4058,7 @@ func testFindRedemption(t *testing.T, assetID uint32) {

func TestRefundReserves(t *testing.T) {
t.Run("eth", func(t *testing.T) { testRefundReserves(t, BipID) })
t.Run("token", func(t *testing.T) { testRefundReserves(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testRefundReserves(t, usdcTokenID) })
}

func testRefundReserves(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -4086,7 +4086,7 @@ func testRefundReserves(t *testing.T, assetID uint32) {
feeWallet = node.tokenParent
assetV0 = *tToken
assetV1 = *tToken
tokenContracts := eth.tokens[simnetTokenID].NetTokens[dex.Simnet].SwapContracts
tokenContracts := eth.tokens[usdcTokenID].NetTokens[dex.Simnet].SwapContracts
tc := *tokenContracts[0]
tc.Gas = *gasesV1
tokenContracts[1] = &tc
Expand Down Expand Up @@ -4155,7 +4155,7 @@ func testRefundReserves(t *testing.T, assetID uint32) {

func TestRedemptionReserves(t *testing.T) {
t.Run("eth", func(t *testing.T) { testRedemptionReserves(t, BipID) })
t.Run("token", func(t *testing.T) { testRedemptionReserves(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testRedemptionReserves(t, usdcTokenID) })
}

func testRedemptionReserves(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -4280,7 +4280,7 @@ func TestReconfigure(t *testing.T) {

func TestSend(t *testing.T) {
t.Run("eth", func(t *testing.T) { testSend(t, BipID) })
t.Run("token", func(t *testing.T) { testSend(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testSend(t, usdcTokenID) })
}

func testSend(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -4363,7 +4363,7 @@ func testSend(t *testing.T, assetID uint32) {

func TestConfirmRedemption(t *testing.T) {
t.Run("eth", func(t *testing.T) { testConfirmRedemption(t, BipID) })
t.Run("token", func(t *testing.T) { testConfirmRedemption(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testConfirmRedemption(t, usdcTokenID) })
}

func testConfirmRedemption(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -5228,7 +5228,7 @@ func TestMarshalMonitoredTx(t *testing.T) {
// and sending will not cause a failure.
func TestEstimateVsActualSendFees(t *testing.T) {
t.Run("eth", func(t *testing.T) { testEstimateVsActualSendFees(t, BipID) })
t.Run("token", func(t *testing.T) { testEstimateVsActualSendFees(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testEstimateVsActualSendFees(t, usdcTokenID) })
}

func testEstimateVsActualSendFees(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -5275,7 +5275,7 @@ func testEstimateVsActualSendFees(t *testing.T, assetID uint32) {

func TestEstimateSendTxFee(t *testing.T) {
t.Run("eth", func(t *testing.T) { testEstimateSendTxFee(t, BipID) })
t.Run("token", func(t *testing.T) { testEstimateSendTxFee(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testEstimateSendTxFee(t, usdcTokenID) })
}

func testEstimateSendTxFee(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -5362,7 +5362,7 @@ func testEstimateSendTxFee(t *testing.T, assetID uint32) {
// contract (that require more gas) are added.
func TestMaxSwapRedeemLots(t *testing.T) {
t.Run("eth", func(t *testing.T) { testMaxSwapRedeemLots(t, BipID) })
t.Run("token", func(t *testing.T) { testMaxSwapRedeemLots(t, simnetTokenID) })
t.Run("token", func(t *testing.T) { testMaxSwapRedeemLots(t, usdcTokenID) })
}

func testMaxSwapRedeemLots(t *testing.T, assetID uint32) {
Expand Down Expand Up @@ -5413,11 +5413,11 @@ func testMaxSwapRedeemLots(t *testing.T, assetID uint32) {
t.Fatalf("expected 63 for max redemptions but got %d", info.MaxRedeemsInTx)
}
} else {
if info.MaxSwapsInTx != 28 {
t.Fatalf("expected 28 for max swaps but got %d", info.MaxSwapsInTx)
if info.MaxSwapsInTx != 20 {
t.Fatalf("expected 20 for max swaps but got %d", info.MaxSwapsInTx)
}
if info.MaxRedeemsInTx != 71 {
t.Fatalf("expected 71 for max redemptions but got %d", info.MaxRedeemsInTx)
if info.MaxRedeemsInTx != 45 {
t.Fatalf("expected 45 for max redemptions but got %d", info.MaxRedeemsInTx)
}
}
}
Expand Down
Loading

0 comments on commit dccd2ec

Please sign in to comment.