@Test public void testSimpleBalance() { StakedTokensParticle minted = mock(StakedTokensParticle.class); Hash hash = mock(Hash.class); when(minted.getAmount()).thenReturn(UInt256.TEN); when(minted.getGranularity()).thenReturn(UInt256.ONE); when(minted.getHash()).thenReturn(hash); RRI token = mock(RRI.class); when(minted.getTokenDefinitionReference()).thenReturn(token); StakedTokenBalanceReducer reducer = new StakedTokenBalanceReducer(); StakedTokenBalanceState tokenBalance = reducer.reduce(new StakedTokenBalanceState(), minted); BigDecimal tenSubunits = TokenUnitConversions.subunitsToUnits(UInt256.TEN); assertThat(tokenBalance.getBalance().get(token).compareTo(tenSubunits)).isEqualTo(0); }
@Override public StakedTokenBalanceState reduce(StakedTokenBalanceState state, Particle p) { if (p instanceof StakedTokensParticle) { return StakedTokenBalanceState.merge(state, (StakedTokensParticle) p); } return state; }
StakedTokenBalanceReducer implements ParticleReducer<StakedTokenBalanceState> { @Override public StakedTokenBalanceState reduce(StakedTokenBalanceState state, Particle p) { if (p instanceof StakedTokensParticle) { return StakedTokenBalanceState.merge(state, (StakedTokensParticle) p); } return state; } }
StakedTokenBalanceReducer implements ParticleReducer<StakedTokenBalanceState> { @Override public StakedTokenBalanceState reduce(StakedTokenBalanceState state, Particle p) { if (p instanceof StakedTokensParticle) { return StakedTokenBalanceState.merge(state, (StakedTokensParticle) p); } return state; }  }
StakedTokenBalanceReducer implements ParticleReducer<StakedTokenBalanceState> { @Override public StakedTokenBalanceState reduce(StakedTokenBalanceState state, Particle p) { if (p instanceof StakedTokensParticle) { return StakedTokenBalanceState.merge(state, (StakedTokensParticle) p); } return state; }  @Override Class<StakedTokenBalanceState> stateClass(); @Override StakedTokenBalanceState initialState(); @Override StakedTokenBalanceState reduce(StakedTokenBalanceState state, Particle p); @Override StakedTokenBalanceState combine(StakedTokenBalanceState state0, StakedTokenBalanceState state1); }
StakedTokenBalanceReducer implements ParticleReducer<StakedTokenBalanceState> { @Override public StakedTokenBalanceState reduce(StakedTokenBalanceState state, Particle p) { if (p instanceof StakedTokensParticle) { return StakedTokenBalanceState.merge(state, (StakedTokensParticle) p); } return state; }  @Override Class<StakedTokenBalanceState> stateClass(); @Override StakedTokenBalanceState initialState(); @Override StakedTokenBalanceState reduce(StakedTokenBalanceState state, Particle p); @Override StakedTokenBalanceState combine(StakedTokenBalanceState state0, StakedTokenBalanceState state1);  }