Skip to content

Commit

Permalink
Avalanche C with Covalent
Browse files Browse the repository at this point in the history
  • Loading branch information
RedRaton committed Jul 10, 2023
1 parent 52e80e9 commit 41bc850
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
package com.allmycoins.balance.avalanche;

import java.util.ArrayList;
import java.util.List;
import com.allmycoins.balance.covalent.CovalentProvider;

import com.allmycoins.balance.PublicAddressBalanceProvider;
import com.allmycoins.balance.etherscan.SingleBalanceJson;
import com.allmycoins.balance.etherscan.TokenTxResultJson;
import com.allmycoins.balance.etherscan.TxToBalances;
import com.allmycoins.json.BalanceJson;
import com.allmycoins.utils.BigDecimalUtils;
import com.allmycoins.utils.RequestUtils;
public final class AvalancheProvider extends CovalentProvider {

public final class AvalancheProvider implements PublicAddressBalanceProvider {

@Override
public List<BalanceJson> balance(String publicAddress) {

// Single AVAX balance
SingleBalanceJson avalancheBalance = RequestUtils.sendRequest(new AvalancheBalanceRequest(publicAddress));
float qty = BigDecimalUtils.decimal18(avalancheBalance.getResult());
BalanceJson balance = new BalanceJson("AVAX", qty, "Avalanche C");

// Tokens
TokenTxResultJson tokenTxResultJson = RequestUtils.sendRequest(new AvalancheTokenTxRequest(publicAddress));
List<BalanceJson> tokenBalances = TxToBalances.txToBalances(tokenTxResultJson, publicAddress, "Avalanche C");

List<BalanceJson> balances = new ArrayList<>();
balances.add(balance);
balances.addAll(tokenBalances);
return balances;
public AvalancheProvider() {
super("Avalanche C wallet", "avalanche-mainnet", "AVALANCHE_C_ADDRESS");
}

@Override
public String privateConfigKey() {
return "AVALANCHE_C_ADDRESS";
}

}
39 changes: 39 additions & 0 deletions src/test/java/com/allmycoins/balance/AvalancheProviderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.allmycoins.balance;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

import org.junit.jupiter.api.Test;

import com.allmycoins.PrivateConfig;
import com.allmycoins.balance.avalanche.AvalancheProvider;
import com.allmycoins.json.BalanceJson;

class AvalancheProviderTest {

@Test
void testBalances() {
PrivateConfig.loadConfigurationFromClassLoader();

AvalancheProvider avalancheProvider = new AvalancheProvider();
List<BalanceJson> balance = avalancheProvider.balances();
assertTrue(balance.size() >= 1);
BalanceJson balanceJson = balance.get(0);

assertEquals("AVAX", balanceJson.getAsset());
assertEquals("Avalanche C wallet", balanceJson.getSrc());
assertTrue(balanceJson.getQty() >= 0.0f);
}

@Test
void testNoBalances() {
PrivateConfig.clearConfiguration();

AvalancheProvider avalancheProvider = new AvalancheProvider();
List<BalanceJson> balance = avalancheProvider.balances();
assertTrue(balance.isEmpty());
}

}
3 changes: 3 additions & 0 deletions src/test/resources/privateConfig.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ALGORAND_ADDRESS = 6JF7P3NV4SO52ZWQJH6O7OWFV5AP6ES4LS6ORKUN7WIPRFLWTZIRJOW2LU
#Ethereum public address for tests
ETH_ADDRESS = 0x2D892CaEf2DfBd28459CCff560dEBceCCdE57694

#Avalanche public address for tests
AVALANCHE_C_ADDRESS = 0x040993fbF458b95871Cd2D73Ee2E09F4AF6d56bB

# MultiversX public address for tests
MULTIVERSX_ADDRESS = erd16x7le8dpkjsafgwjx0e5kw94evsqw039rwp42m2j9eesd88x8zzs75tzry

Expand Down

0 comments on commit 41bc850

Please sign in to comment.