diff --git a/examples/lottery/.gitignore b/examples/lottery/.gitignore new file mode 100644 index 0000000000..b28696155d --- /dev/null +++ b/examples/lottery/.gitignore @@ -0,0 +1,2 @@ +outputs/ +build/ diff --git a/examples/lottery/README.md b/examples/lottery/README.md new file mode 100644 index 0000000000..897dae6206 --- /dev/null +++ b/examples/lottery/README.md @@ -0,0 +1,8 @@ +# lottery.aleo + +## Build Guide + +To compile this Aleo program, run: +```bash +aleo build +``` diff --git a/examples/lottery/inputs/lottery.in b/examples/lottery/inputs/lottery.in new file mode 100644 index 0000000000..4113519304 --- /dev/null +++ b/examples/lottery/inputs/lottery.in @@ -0,0 +1,4 @@ +// The program input for lottery/src/main.leo +[main] +public a: u32 = 1u32; +b: u32 = 2u32; diff --git a/examples/lottery/program.json b/examples/lottery/program.json new file mode 100644 index 0000000000..b66b29cf1f --- /dev/null +++ b/examples/lottery/program.json @@ -0,0 +1,10 @@ +{ + "program": "lottery.aleo", + "version": "0.0.0", + "description": "", + "development": { + "private_key": "APrivateKey1zkpJrHD9orEuTpL8dDnSBZo6VyKWdbrk3VJfcwEv9SsQBN2", + "address": "aleo1dvx603addv7c2uqj6ksm9hccaypzn0ngus4n2vygvdlhqvkcyyfqvh4zdz" + }, + "license": "MIT" +} diff --git a/examples/lottery/src/main.leo b/examples/lottery/src/main.leo new file mode 100644 index 0000000000..c36dcf216b --- /dev/null +++ b/examples/lottery/src/main.leo @@ -0,0 +1,30 @@ +// The 'lottery' program. +program lottery.aleo { + + mapping num_winners: u8 => u8; + + record Ticket { + owner: address, + } + + transition play() -> u32 { + let ticket: Ticket = Ticket { + owner: self.caller, + }; + return ticket then finalize(); + } + + finalize play() { + // Check that the lottery has not expired. + assert(block.height <= 1000); + + // Randomly select whether or not the ticket is a winner. + assert(ChaCha::rand_bool()); + + // Check that the maximum number of winners have not been reached. + let winners: u8 = num_winners.get_or_use(0u8); + assert(winners < 5u8); + num_winners.set(0u8, winners + 1u8); + + } +} diff --git a/tests/expectations/compiler/finalize/rand.out b/tests/expectations/compiler/finalize/rand.out new file mode 100644 index 0000000000..a450196340 --- /dev/null +++ b/tests/expectations/compiler/finalize/rand.out @@ -0,0 +1,12 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - - initial_ast: 2d7b208912c97c514488786ee171503bfe6d230fb6f0f35725fdcc0d217dad20 + unrolled_ast: 2d7b208912c97c514488786ee171503bfe6d230fb6f0f35725fdcc0d217dad20 + ssa_ast: d31261c1b1ffc59dae4f917070deae35adcb480707a00e4ce900458f962855cc + flattened_ast: 57633e91a7d54fa5f5ec007863b135a0b1bca23f3016c2bc01ab8293ad2f59d4 + inlined_ast: 57633e91a7d54fa5f5ec007863b135a0b1bca23f3016c2bc01ab8293ad2f59d4 + dce_ast: 09659efca22ece8c63c317e0e22e1400871541e2d40a6604e073e64a7fc54153 + bytecode: 268f9afb6b8472b88b0c91f927b0cd4a69c10ad4457714dbb6faddeee5405cc6 + warnings: "" diff --git a/tests/tests/compiler/finalize/rand.leo b/tests/tests/compiler/finalize/rand.leo index 738892e798..1ea0493297 100644 --- a/tests/tests/compiler/finalize/rand.leo +++ b/tests/tests/compiler/finalize/rand.leo @@ -25,5 +25,6 @@ program test.aleo { let m: u32 = ChaCha::rand_u32(); let n: u64 = ChaCha::rand_u64(); let o: u128 = ChaCha::rand_u128(); + assert(b); } }