Search in sources :

Example 1 with CMError

use of com.radixdlt.constraintmachine.CMError 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();
}
Also used : HashCode(com.google.common.hash.HashCode) CMError(com.radixdlt.constraintmachine.CMError) ECKeyPair(com.radixdlt.crypto.ECKeyPair) CMInstruction(com.radixdlt.constraintmachine.CMInstruction) RadixAddress(com.radixdlt.identifiers.RadixAddress) TransferrableTokensParticle(com.radixdlt.application.tokens.TransferrableTokensParticle) Test(org.junit.Test)

Example 2 with CMError

use of com.radixdlt.constraintmachine.CMError 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();
}
Also used : HashCode(com.google.common.hash.HashCode) CMError(com.radixdlt.constraintmachine.CMError) ECKeyPair(com.radixdlt.crypto.ECKeyPair) CMInstruction(com.radixdlt.constraintmachine.CMInstruction) RadixAddress(com.radixdlt.identifiers.RadixAddress) TransferrableTokensParticle(com.radixdlt.application.tokens.TransferrableTokensParticle) Test(org.junit.Test)

Example 3 with CMError

use of com.radixdlt.constraintmachine.CMError 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();
}
Also used : HashCode(com.google.common.hash.HashCode) CMError(com.radixdlt.constraintmachine.CMError) ECKeyPair(com.radixdlt.crypto.ECKeyPair) CMInstruction(com.radixdlt.constraintmachine.CMInstruction) RadixAddress(com.radixdlt.identifiers.RadixAddress) TransferrableTokensParticle(com.radixdlt.application.tokens.TransferrableTokensParticle) Test(org.junit.Test)

Example 4 with CMError

use of com.radixdlt.constraintmachine.CMError 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();
}
Also used : HashCode(com.google.common.hash.HashCode) CMError(com.radixdlt.constraintmachine.CMError) ECKeyPair(com.radixdlt.crypto.ECKeyPair) CMInstruction(com.radixdlt.constraintmachine.CMInstruction) RadixAddress(com.radixdlt.identifiers.RadixAddress) TransferrableTokensParticle(com.radixdlt.application.tokens.TransferrableTokensParticle) Test(org.junit.Test)

Aggregations

HashCode (com.google.common.hash.HashCode)4 TransferrableTokensParticle (com.radixdlt.application.tokens.TransferrableTokensParticle)4 CMError (com.radixdlt.constraintmachine.CMError)4 CMInstruction (com.radixdlt.constraintmachine.CMInstruction)4 ECKeyPair (com.radixdlt.crypto.ECKeyPair)4 RadixAddress (com.radixdlt.identifiers.RadixAddress)4 Test (org.junit.Test)4