use of com.radixdlt.identifiers.RadixAddress in project radixdlt by radixdlt.
the class CMTokensTest method when_correct_1_input_to_2_outputs_token_send__then_should_not_error.
@Test
public void when_correct_1_input_to_2_outputs_token_send__then_should_not_error() {
ECKeyPair sender = ECKeyPair.generateNew();
RadixAddress senderAddress = new RadixAddress((byte) 0, sender.getPublicKey());
RadixAddress receiverAddress = new RadixAddress((byte) 0, ECKeyPair.generateNew().getPublicKey());
TransferrableTokensParticle input = new TransferrableTokensParticle(senderAddress, UInt256.THREE, this.granularity, this.token, this.permissions);
TransferrableTokensParticle output0 = new TransferrableTokensParticle(senderAddress, UInt256.TWO, UInt256.ONE, this.token, this.permissions);
TransferrableTokensParticle output1 = new TransferrableTokensParticle(receiverAddress, UInt256.ONE, this.granularity, this.token, this.permissions);
HashCode witness = HashUtils.random256();
CMInstruction cmInstruction = new CMInstruction(ImmutableList.of(CMMicroInstruction.checkSpinAndPush(input, Spin.UP), CMMicroInstruction.checkSpinAndPush(output0, Spin.NEUTRAL), CMMicroInstruction.checkSpinAndPush(output1, Spin.NEUTRAL), CMMicroInstruction.particleGroup()), ImmutableMap.of(sender.euid(), sender.sign(witness)));
Optional<CMError> error = cm.validate(cmInstruction, witness, PermissionLevel.USER);
error.map(CMError::getCmValidationState).ifPresent(System.out::println);
assertThat(error).isEmpty();
}
use of com.radixdlt.identifiers.RadixAddress in project radixdlt by radixdlt.
the class CMTokensTest method when_correct_1_to_1_token_send__then_should_not_error.
@Test
public void when_correct_1_to_1_token_send__then_should_not_error() {
ECKeyPair sender = ECKeyPair.generateNew();
RadixAddress senderAddress = new RadixAddress((byte) 0, sender.getPublicKey());
RadixAddress receiverAddress = new RadixAddress((byte) 0, ECKeyPair.generateNew().getPublicKey());
TransferrableTokensParticle input = new TransferrableTokensParticle(senderAddress, UInt256.ONE, this.granularity, this.token, this.permissions);
TransferrableTokensParticle output = new TransferrableTokensParticle(receiverAddress, UInt256.ONE, this.granularity, this.token, this.permissions);
HashCode witness = HashUtils.random256();
CMInstruction cmInstruction = new CMInstruction(ImmutableList.of(CMMicroInstruction.checkSpinAndPush(input, Spin.UP), CMMicroInstruction.checkSpinAndPush(output, Spin.NEUTRAL), CMMicroInstruction.particleGroup()), ImmutableMap.of(sender.euid(), sender.sign(witness)));
Optional<CMError> error = cm.validate(cmInstruction, witness, PermissionLevel.USER);
assertThat(error).isEmpty();
}
use of com.radixdlt.identifiers.RadixAddress in project radixdlt by radixdlt.
the class CMTokensTest method when_another_correct_2_inputs_to_1_output_token_send__then_should_not_error.
@Test
public void when_another_correct_2_inputs_to_1_output_token_send__then_should_not_error() {
ECKeyPair sender = ECKeyPair.generateNew();
RadixAddress senderAddress = new RadixAddress((byte) 0, sender.getPublicKey());
RadixAddress receiverAddress = new RadixAddress((byte) 0, ECKeyPair.generateNew().getPublicKey());
TransferrableTokensParticle input0 = new TransferrableTokensParticle(senderAddress, UInt256.ONE, this.granularity, this.token, this.permissions);
TransferrableTokensParticle input1 = new TransferrableTokensParticle(senderAddress, UInt256.TWO, UInt256.ONE, this.token, this.permissions);
TransferrableTokensParticle output = new TransferrableTokensParticle(receiverAddress, UInt256.THREE, this.granularity, this.token, this.permissions);
HashCode witness = HashUtils.random256();
CMInstruction cmInstruction = new CMInstruction(ImmutableList.of(CMMicroInstruction.checkSpinAndPush(output, Spin.NEUTRAL), CMMicroInstruction.checkSpinAndPush(input0, Spin.UP), CMMicroInstruction.checkSpinAndPush(input1, Spin.UP), CMMicroInstruction.particleGroup()), ImmutableMap.of(sender.euid(), sender.sign(witness)));
Optional<CMError> error = cm.validate(cmInstruction, witness, PermissionLevel.USER);
error.map(CMError::getCmValidationState).ifPresent(System.out::println);
assertThat(error).isEmpty();
}
use of com.radixdlt.identifiers.RadixAddress in project radixdlt by radixdlt.
the class CMTokensTest method when_correct_2_inputs_to_1_output_token_send__then_should_not_error.
@Test
public void when_correct_2_inputs_to_1_output_token_send__then_should_not_error() {
ECKeyPair sender = ECKeyPair.generateNew();
RadixAddress senderAddress = new RadixAddress((byte) 0, sender.getPublicKey());
RadixAddress receiverAddress = new RadixAddress((byte) 0, ECKeyPair.generateNew().getPublicKey());
TransferrableTokensParticle input0 = new TransferrableTokensParticle(senderAddress, UInt256.ONE, this.granularity, this.token, this.permissions);
TransferrableTokensParticle input1 = new TransferrableTokensParticle(senderAddress, UInt256.TWO, UInt256.ONE, this.token, this.permissions);
TransferrableTokensParticle output = new TransferrableTokensParticle(receiverAddress, UInt256.THREE, this.granularity, this.token, this.permissions);
HashCode witness = HashUtils.random256();
CMInstruction cmInstruction = new CMInstruction(ImmutableList.of(CMMicroInstruction.checkSpinAndPush(input0, Spin.UP), CMMicroInstruction.checkSpinAndPush(output, Spin.NEUTRAL), CMMicroInstruction.checkSpinAndPush(input1, Spin.UP), CMMicroInstruction.particleGroup()), ImmutableMap.of(sender.euid(), sender.sign(witness)));
Optional<CMError> error = cm.validate(cmInstruction, witness, PermissionLevel.USER);
error.map(CMError::getCmValidationState).ifPresent(System.out::println);
assertThat(error).isEmpty();
}
use of com.radixdlt.identifiers.RadixAddress in project radixdlt by radixdlt.
the class CMTokensTest method setup.
@Before
public void setup() {
// Build the engine based on the constraint machine configured by the AtomOS
CMAtomOS cmAtomOS = new CMAtomOS();
cmAtomOS.load(new TokensConstraintScrypt());
this.cm = new ConstraintMachine.Builder().setParticleStaticCheck(cmAtomOS.buildParticleStaticCheck()).setParticleTransitionProcedures(cmAtomOS.buildTransitionProcedures()).build();
RadixAddress tokenAddress = new RadixAddress((byte) 0, ECKeyPair.generateNew().getPublicKey());
this.token = RRI.of(tokenAddress, "TEST");
this.granularity = UInt256.ONE;
this.permissions = ImmutableMap.of(TokenTransition.BURN, TokenPermission.TOKEN_OWNER_ONLY, TokenTransition.MINT, TokenPermission.TOKEN_OWNER_ONLY);
}
Aggregations