Search in sources :

Example 1 with RadixAddress

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();
}
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 RadixAddress

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();
}
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 RadixAddress

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();
}
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 RadixAddress

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();
}
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 5 with RadixAddress

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);
}
Also used : TokensConstraintScrypt(com.radixdlt.application.tokens.TokensConstraintScrypt) RadixAddress(com.radixdlt.identifiers.RadixAddress) CMAtomOS(com.radixdlt.atomos.CMAtomOS) Before(org.junit.Before)

Aggregations

RadixAddress (com.radixdlt.identifiers.RadixAddress)5 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 Test (org.junit.Test)4 TokensConstraintScrypt (com.radixdlt.application.tokens.TokensConstraintScrypt)1 CMAtomOS (com.radixdlt.atomos.CMAtomOS)1 Before (org.junit.Before)1