mirror of
https://github.com/sparrowwallet/hummingbird.git
synced 2024-12-26 01:56:45 +00:00
CryptoCoinInfo fix to avoid crashes and to support ETHEREUM value in Type enum
This commit is contained in:
parent
286d9843df
commit
236f91a7e0
2 changed files with 44 additions and 3 deletions
|
@ -17,12 +17,12 @@ public class CryptoCoinInfo extends RegistryItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CryptoCoinInfo(Type type, Network network) {
|
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);
|
this.network = (network != null ? network.ordinal() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return type == null ? Type.BITCOIN : Type.values()[type];
|
return type == null ? Type.BITCOIN : Type.getTypeFromValue(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Network getNetwork() {
|
public Network getNetwork() {
|
||||||
|
@ -65,7 +65,23 @@ public class CryptoCoinInfo extends RegistryItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Type {
|
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 {
|
public enum Network {
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
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 testNullTypeCoinInfo() {
|
||||||
|
CryptoCoinInfo coinInfo = new CryptoCoinInfo(null, CryptoCoinInfo.Network.MAINNET);
|
||||||
|
Assert.assertSame(coinInfo.getType(), CryptoCoinInfo.Type.BITCOIN);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue