-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate security/initializable (#592)
* update cairo * fix path * add security mod * add initializable * add tests * Update src/openzeppelin/security/initializable.cairo Co-authored-by: Martín Triay <martriay@gmail.com> * remove underscore * add internal macros --------- Co-authored-by: Martín Triay <martriay@gmail.com>
- Loading branch information
1 parent
a54e98c
commit 91dcad3
Showing
6 changed files
with
38 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod security; | ||
mod token; | ||
mod tests; |
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 @@ | ||
mod initializable; |
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,17 @@ | ||
#[contract] | ||
mod Initializable { | ||
struct Storage { | ||
initialized: bool, | ||
} | ||
|
||
#[internal] | ||
fn is_initialized() -> bool { | ||
initialized::read() | ||
} | ||
|
||
#[internal] | ||
fn initialize() { | ||
assert(!is_initialized(), 'Contract already initialized'); | ||
initialized::write(true); | ||
} | ||
} |
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 test_erc20; | ||
mod test_initializable; |
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,17 @@ | ||
use openzeppelin::security::initializable::Initializable; | ||
|
||
#[test] | ||
#[available_gas(2000000)] | ||
fn test_initialize() { | ||
assert(!Initializable::is_initialized(),'Should not be initialized'); | ||
Initializable::initialize(); | ||
assert(Initializable::is_initialized(),'Should be initialized'); | ||
} | ||
|
||
#[test] | ||
#[available_gas(2000000)] | ||
#[should_panic(expected = ('Contract already initialized', ))] | ||
fn test_initialize_when_initialized() { | ||
Initializable::initialize(); | ||
Initializable::initialize(); | ||
} |