diff --git a/src/main/java/com/allmycoins/balance/avalanche/AvalancheProvider.java b/src/main/java/com/allmycoins/balance/avalanche/AvalancheProvider.java index fbd5590..6f10b4e 100644 --- a/src/main/java/com/allmycoins/balance/avalanche/AvalancheProvider.java +++ b/src/main/java/com/allmycoins/balance/avalanche/AvalancheProvider.java @@ -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 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 tokenBalances = TxToBalances.txToBalances(tokenTxResultJson, publicAddress, "Avalanche C"); - - List 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"; - } - } diff --git a/src/test/java/com/allmycoins/balance/AvalancheProviderTest.java b/src/test/java/com/allmycoins/balance/AvalancheProviderTest.java new file mode 100644 index 0000000..b39f688 --- /dev/null +++ b/src/test/java/com/allmycoins/balance/AvalancheProviderTest.java @@ -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 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 balance = avalancheProvider.balances(); + assertTrue(balance.isEmpty()); + } + +} diff --git a/src/test/resources/privateConfig.properties b/src/test/resources/privateConfig.properties index 4932be7..390dc84 100644 --- a/src/test/resources/privateConfig.properties +++ b/src/test/resources/privateConfig.properties @@ -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