mirror of
https://github.com/sparrowwallet/hummingbird.git
synced 2024-12-26 01:56:45 +00:00
Merge pull request #5 from proxyco/fix/crypto-coin-crash
CryptoCoinInfo crash fix for Ethereum
This commit is contained in:
commit
8f6cb0a662
2 changed files with 56 additions and 3 deletions
|
@ -17,12 +17,12 @@ public class CryptoCoinInfo extends RegistryItem {
|
|||
}
|
||||
|
||||
public CryptoCoinInfo(Type type, Network network) {
|
||||
this.type = (type != null ? type.ordinal() : null);
|
||||
this.type = (type != null ? type.typeValue : null);
|
||||
this.network = (network != null ? network.ordinal() : null);
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type == null ? Type.BITCOIN : Type.values()[type];
|
||||
return type == null ? Type.BITCOIN : Type.getTypeFromValue(type);
|
||||
}
|
||||
|
||||
public Network getNetwork() {
|
||||
|
@ -65,7 +65,23 @@ public class CryptoCoinInfo extends RegistryItem {
|
|||
}
|
||||
|
||||
public enum Type {
|
||||
BITCOIN
|
||||
BITCOIN(0), ETHEREUM(60);
|
||||
|
||||
Integer typeValue;
|
||||
|
||||
Type(Integer typeValue) {
|
||||
this.typeValue = typeValue;
|
||||
}
|
||||
|
||||
static Type getTypeFromValue(int value) {
|
||||
for (int i = 0; i < Type.values().length; i++) {
|
||||
Type current = Type.values()[i];
|
||||
if(value == current.typeValue) {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Network {
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.sparrowwallet.hummingbird.registry;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CryptoCoinInfoTest {
|
||||
|
||||
@Test
|
||||
public void testBitcoinCoinInfo() {
|
||||
CryptoCoinInfo coinInfo = new CryptoCoinInfo(CryptoCoinInfo.Type.BITCOIN, CryptoCoinInfo.Network.MAINNET);
|
||||
Assert.assertSame(coinInfo.getType().typeValue, CryptoCoinInfo.Type.BITCOIN.typeValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEthereumCoinInfo() {
|
||||
CryptoCoinInfo coinInfo = new CryptoCoinInfo(CryptoCoinInfo.Type.ETHEREUM, CryptoCoinInfo.Network.MAINNET);
|
||||
Assert.assertSame(coinInfo.getType().typeValue, CryptoCoinInfo.Type.ETHEREUM.typeValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBitcoinTypeCoinInfo() {
|
||||
CryptoCoinInfo coinInfo = new CryptoCoinInfo(CryptoCoinInfo.Type.BITCOIN, CryptoCoinInfo.Network.MAINNET);
|
||||
Assert.assertSame(coinInfo.getType(), CryptoCoinInfo.Type.BITCOIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEthereumTypeCoinInfo() {
|
||||
CryptoCoinInfo coinInfo = new CryptoCoinInfo(CryptoCoinInfo.Type.ETHEREUM, CryptoCoinInfo.Network.MAINNET);
|
||||
Assert.assertSame(coinInfo.getType(), CryptoCoinInfo.Type.ETHEREUM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullTypeCoinInfo() {
|
||||
CryptoCoinInfo coinInfo = new CryptoCoinInfo(null, CryptoCoinInfo.Network.MAINNET);
|
||||
Assert.assertSame(coinInfo.getType(), CryptoCoinInfo.Type.BITCOIN);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue