@Test public void testTokenWithMint() { final UInt256 hundred = UInt256.TEN.pow(2); MutableSupplyTokenDefinitionParticle tokenDefinitionParticle = mock(MutableSupplyTokenDefinitionParticle.class); RRI tokenRef = mock(RRI.class); when(tokenDefinitionParticle.getRRI()).thenReturn(tokenRef); when(tokenDefinitionParticle.getName()).thenReturn("Name"); when(tokenDefinitionParticle.getSymbol()).thenReturn("ISO"); when(tokenDefinitionParticle.getDescription()).thenReturn("Desc"); when(tokenDefinitionParticle.getGranularity()).thenReturn(UInt256.ONE); when(tokenDefinitionParticle.getTokenPermissions()).thenReturn(Collections.singletonMap(TokenTransition.MINT, TokenPermission.TOKEN_OWNER_ONLY)); TransferrableTokensParticle minted = mock(TransferrableTokensParticle.class); when(minted.getAmount()).thenReturn(hundred); when(minted.getTokenDefinitionReference()).thenReturn(tokenRef); UnallocatedTokensParticle unallocatedTokensParticle = mock(UnallocatedTokensParticle.class); when(unallocatedTokensParticle.getAmount()).thenReturn(UInt256.MAX_VALUE.subtract(hundred)); when(unallocatedTokensParticle.getTokDefRef()).thenReturn(tokenRef); when(unallocatedTokensParticle.euid()).thenReturn(EUID.ONE); TokenDefinitionsReducer tokenDefinitionsReducer = new TokenDefinitionsReducer(); TokenDefinitionsState state1 = tokenDefinitionsReducer.reduce(TokenDefinitionsState.init(), tokenDefinitionParticle); TokenDefinitionsState state2 = tokenDefinitionsReducer.reduce(state1, unallocatedTokensParticle); TokenDefinitionsState state3 = tokenDefinitionsReducer.reduce(state2, minted); assertThat(state3.getState().get(tokenRef).getTotalSupply()).isEqualTo(TokenUnitConversions.subunitsToUnits(hundred)); assertThat(state3.getState().get(tokenRef).getName()).isEqualTo("Name"); assertThat(state3.getState().get(tokenRef).getIso()).isEqualTo("ISO"); assertThat(state3.getState().get(tokenRef).getTokenSupplyType()).isEqualTo(TokenSupplyType.MUTABLE); }
@Override public TokenDefinitionsState reduce(TokenDefinitionsState state, Particle p) { if (p instanceof MutableSupplyTokenDefinitionParticle) { return reduceInternal(state, (MutableSupplyTokenDefinitionParticle) p); } else if (p instanceof FixedSupplyTokenDefinitionParticle) { return reduceInternal(state, (FixedSupplyTokenDefinitionParticle) p); } else if (p instanceof UnallocatedTokensParticle) { UnallocatedTokensParticle u = (UnallocatedTokensParticle) p; return state.mergeUnallocated(u); } return state; }
TokenDefinitionsReducer implements ParticleReducer<TokenDefinitionsState> { @Override public TokenDefinitionsState reduce(TokenDefinitionsState state, Particle p) { if (p instanceof MutableSupplyTokenDefinitionParticle) { return reduceInternal(state, (MutableSupplyTokenDefinitionParticle) p); } else if (p instanceof FixedSupplyTokenDefinitionParticle) { return reduceInternal(state, (FixedSupplyTokenDefinitionParticle) p); } else if (p instanceof UnallocatedTokensParticle) { UnallocatedTokensParticle u = (UnallocatedTokensParticle) p; return state.mergeUnallocated(u); } return state; } }
TokenDefinitionsReducer implements ParticleReducer<TokenDefinitionsState> { @Override public TokenDefinitionsState reduce(TokenDefinitionsState state, Particle p) { if (p instanceof MutableSupplyTokenDefinitionParticle) { return reduceInternal(state, (MutableSupplyTokenDefinitionParticle) p); } else if (p instanceof FixedSupplyTokenDefinitionParticle) { return reduceInternal(state, (FixedSupplyTokenDefinitionParticle) p); } else if (p instanceof UnallocatedTokensParticle) { UnallocatedTokensParticle u = (UnallocatedTokensParticle) p; return state.mergeUnallocated(u); } return state; }  }
TokenDefinitionsReducer implements ParticleReducer<TokenDefinitionsState> { @Override public TokenDefinitionsState reduce(TokenDefinitionsState state, Particle p) { if (p instanceof MutableSupplyTokenDefinitionParticle) { return reduceInternal(state, (MutableSupplyTokenDefinitionParticle) p); } else if (p instanceof FixedSupplyTokenDefinitionParticle) { return reduceInternal(state, (FixedSupplyTokenDefinitionParticle) p); } else if (p instanceof UnallocatedTokensParticle) { UnallocatedTokensParticle u = (UnallocatedTokensParticle) p; return state.mergeUnallocated(u); } return state; }  @Override Class<TokenDefinitionsState> stateClass(); @Override TokenDefinitionsState initialState(); @Override TokenDefinitionsState reduce(TokenDefinitionsState state, Particle p); @Override TokenDefinitionsState combine(TokenDefinitionsState state0, TokenDefinitionsState state1); }
TokenDefinitionsReducer implements ParticleReducer<TokenDefinitionsState> { @Override public TokenDefinitionsState reduce(TokenDefinitionsState state, Particle p) { if (p instanceof MutableSupplyTokenDefinitionParticle) { return reduceInternal(state, (MutableSupplyTokenDefinitionParticle) p); } else if (p instanceof FixedSupplyTokenDefinitionParticle) { return reduceInternal(state, (FixedSupplyTokenDefinitionParticle) p); } else if (p instanceof UnallocatedTokensParticle) { UnallocatedTokensParticle u = (UnallocatedTokensParticle) p; return state.mergeUnallocated(u); } return state; }  @Override Class<TokenDefinitionsState> stateClass(); @Override TokenDefinitionsState initialState(); @Override TokenDefinitionsState reduce(TokenDefinitionsState state, Particle p); @Override TokenDefinitionsState combine(TokenDefinitionsState state0, TokenDefinitionsState state1);  }