private BigInteger getRawValue(BigDecimal amount, int decimals) { return toWei(amount, decimals).toBigInteger(); } }
@Test public void statisticsReturnsTotalAvailableFunding() { TokenAmountDto tokenAmount = new TokenAmountDto(fnd.getAddress(), EthUtil.toWei(BigDecimal.TEN, fnd.getDecimals())); TokenAmountDto tokenAmount2 = new TokenAmountDto(zrx.getAddress(), EthUtil.toWei(BigDecimal.ONE, zrx.getDecimals())); when(fundRepository.getAmountPerTokenWhereRequestHasStatusFunded()).thenReturn(Arrays.asList(tokenAmount, tokenAmount2)); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(fnd.getSymbol()) .tokenAddress(fnd.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount.getTotalAmount(), fnd.getDecimals())) .build())).thenReturn(10.0); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(zrx.getSymbol()) .tokenAddress(zrx.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount2.getTotalAmount(), zrx.getDecimals())) .build())).thenReturn(20.0); StatisticsDto result = statisticsService.getStatistics(); assertThat(result.getTotalAvailableFunding()).isEqualTo(30.0); }
@Test void map() { final String tokenAddress = "dafsd"; final String symbol = "ZRX"; final BigDecimal rawBalance = new BigDecimal("1000000000000000000"); final int decimals = 18; final TokenInfoDto tokenInfoDto = TokenInfoDto.builder().address(tokenAddress).symbol(symbol).decimals(decimals).build(); when(tokenInfoService.getTokenInfo(tokenAddress)).thenReturn(tokenInfoDto); final TokenValueDto result = mapper.map(tokenAddress, rawBalance); assertThat(result.getTokenAddress()).isEqualTo(tokenAddress); assertThat(result.getTokenSymbol()).isEqualTo(symbol); assertThat(result.getTotalAmount()).isEqualTo(fromWei(rawBalance, decimals)); }
@Test public void statisticsReturnsMostFundedTechnology() { TokenAmountDto tokenAmount = new TokenAmountDto(fnd.getAddress(), EthUtil.toWei(BigDecimal.TEN, fnd.getDecimals())); TokenAmountDto tokenAmount2 = new TokenAmountDto(zrx.getAddress(), EthUtil.toWei(BigDecimal.ONE, zrx.getDecimals())); List<Object[]> requests = Arrays.asList( createObject("Java", fnd.getAddress(), tokenAmount.getTotalAmount()), createObject("Python", zrx.getAddress(), tokenAmount2.getTotalAmount()) ); when(fundRepository.getAmountPerTokenPerTechnologyWhereRequestHasStatusFunded()).thenReturn(requests); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(fnd.getSymbol()) .tokenAddress(fnd.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount.getTotalAmount(), fnd.getDecimals())) .build())).thenReturn(10.0); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(zrx.getSymbol()) .tokenAddress(zrx.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount2.getTotalAmount(), zrx.getDecimals())) .build())).thenReturn(20.0); StatisticsDto result = statisticsService.getStatistics(); assertThat(result.getMostFundedTechnology()).isEqualTo("Python"); }
public TokenValueDto map(final String tokenAddress, final BigDecimal rawBalance) { final TokenInfoDto tokenInfo = tokenInfoService.getTokenInfo(tokenAddress); return tokenInfo == null ? null : TokenValueDto.builder() .tokenAddress(tokenInfo.getAddress()) .tokenSymbol(tokenInfo.getSymbol()) .totalAmount(fromWei(rawBalance, tokenInfo.getDecimals())) .build(); } }
@Test public void statisticsReturnsMostFundedProject() { TokenAmountDto tokenAmount = new TokenAmountDto(fnd.getAddress(), EthUtil.toWei(BigDecimal.TEN, fnd.getDecimals())); TokenAmountDto tokenAmount2 = new TokenAmountDto(zrx.getAddress(), EthUtil.toWei(BigDecimal.ONE, zrx.getDecimals())); List<Object[]> requests = Arrays.asList( createObject("FundRequest", fnd.getAddress(), tokenAmount.getTotalAmount()), createObject("Dock", zrx.getAddress(), tokenAmount2.getTotalAmount()) ); when(fundRepository.getAmountPerTokenPerProjectWhereRequestHasStatusFunded()).thenReturn(requests); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(fnd.getSymbol()) .tokenAddress(fnd.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount.getTotalAmount(), fnd.getDecimals())) .build())).thenReturn(10.0); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(zrx.getSymbol()) .tokenAddress(zrx.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount2.getTotalAmount(), zrx.getDecimals())) .build())).thenReturn(20.0); StatisticsDto result = statisticsService.getStatistics(); assertThat(result.getMostFundedProject()).isEqualTo("Dock"); }
@Override public TokenValueDto map(final TokenValue tokenValue) { final TokenInfoDto tokenInfo = tokenInfoService.getTokenInfo(tokenValue.getTokenAddress()); return TokenValueDto.builder() .tokenAddress(tokenValue.getTokenAddress()) .tokenSymbol(tokenInfo.getSymbol()) .totalAmount(fromWei(tokenValue.getAmountInWei(), tokenInfo.getDecimals())) .build(); } }
private BigInteger toWei(PendingFundCommand command) { final TokenInfoDto tokenInfo = tokenInfoService.getTokenInfo(command.getTokenAddress()); return EthUtil.toWei(new BigDecimal(command.getAmount()), tokenInfo.getDecimals()).toBigInteger(); }
private double mapToUsd(TokenAmountDto f) { TokenInfoDto tokenInfo = tokenInfoService.getTokenInfo(f.getTokenAddress()); TokenValueDto dto = TokenValueDto.builder() .totalAmount(fromWei(f.getTotalAmount(), tokenInfo.getDecimals())) .tokenAddress(f.getTokenAddress()) .tokenSymbol(tokenInfo.getSymbol()) .build(); return fiatService.getUsdPrice(dto); } }