forked from visoftsolutions/noir_rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: simplify and fix DocsExample contract, e2e singleton + codegen…
… to not show internal methods (AztecProtocol#4169) DocsExample contrtc is the only place we use singleton. And it wasn't working so fixed and massively simplified it Also sneaked in a change where codegen doesn't show internal methods anymore Singleton uses `owner` and unsure if it is really needed
- Loading branch information
1 parent
144ae71
commit 38d262e
Showing
11 changed files
with
159 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Fr, Wallet } from '@aztec/aztec.js'; | ||
import { DocsExampleContract } from '@aztec/noir-contracts'; | ||
|
||
import { setup } from './fixtures/utils.js'; | ||
|
||
describe('e2e_singleton', () => { | ||
let wallet: Wallet; | ||
|
||
let teardown: () => Promise<void>; | ||
let contract: DocsExampleContract; | ||
|
||
beforeAll(async () => { | ||
({ teardown, wallet } = await setup()); | ||
contract = await DocsExampleContract.deploy(wallet).send().deployed(); | ||
// sets card value to 1 and leader to sender. | ||
await contract.methods.initialize_private(Fr.random(), 1).send().wait(); | ||
}, 25_000); | ||
|
||
afterAll(() => teardown()); | ||
|
||
// Singleton tests: | ||
it('can read singleton and replace/update it in the same call', async () => { | ||
await expect(contract.methods.update_legendary_card(Fr.random(), 0).simulate()).rejects.toThrowError( | ||
'Assertion failed: can only update to higher value', | ||
); | ||
|
||
const newPoints = 3n; | ||
await contract.methods.update_legendary_card(Fr.random(), newPoints).send().wait(); | ||
expect((await contract.methods.get_leader().view()).points).toEqual(newPoints); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
yarn-project/noir-contracts/contracts/docs_example_contract/src/actions.nr
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
yarn-project/noir-contracts/contracts/docs_example_contract/src/types.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod card_note; | ||
mod leader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
yarn-project/noir-contracts/contracts/docs_example_contract/src/types/leader.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use dep::aztec::protocol_types::address::AztecAddress; | ||
use dep::aztec::types::type_serialization::TypeSerializationInterface; | ||
|
||
// Shows how to create a custom struct in Public | ||
struct Leader { | ||
account: AztecAddress, | ||
points: u8, | ||
} | ||
|
||
global LEADER_SERIALIZED_LEN: Field = 2; | ||
|
||
fn deserialize(fields: [Field; LEADER_SERIALIZED_LEN]) -> Leader { | ||
Leader { account: AztecAddress::from_field(fields[0]), points: fields[1] as u8 } | ||
} | ||
|
||
fn serialize(leader: Leader) -> [Field; LEADER_SERIALIZED_LEN] { | ||
[leader.account.to_field(), leader.points as Field] | ||
} | ||
|
||
global LeaderSerializationMethods = TypeSerializationInterface { | ||
deserialize, | ||
serialize, | ||
}; |