-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5964c08
commit 564cce6
Showing
7 changed files
with
174 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore build artifacts from the local tests sub-crate. | ||
/target/ | ||
|
||
# Ignore backup files creates by cargo fmt. | ||
**/*.rs.bk | ||
|
||
# Remove Cargo.lock when creating an executable, leave it for libraries | ||
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock | ||
Cargo.lock |
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,36 @@ | ||
[package] | ||
name = "nonces" | ||
version= "4.0.0-beta" | ||
authors = ["Brushfam <[email protected]>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
ink = { version = "4.2.1", default-features = false} | ||
|
||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } | ||
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } | ||
|
||
# These dependencies | ||
openbrush = { path = "../..", default-features = false, features = ["utils"] } | ||
|
||
[dev-dependencies] | ||
ink_e2e = "4.2.1" | ||
test_helpers = { path = "../test_helpers", default-features = false } | ||
|
||
[lib] | ||
path = "lib.rs" | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"ink/std", | ||
"scale/std", | ||
"scale-info/std", | ||
# These dependencies | ||
"openbrush/std", | ||
] | ||
ink-as-dependency = [] | ||
e2e-tests = [] | ||
|
||
[profile.dev] | ||
codegen-units = 16 |
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,55 @@ | ||
#![cfg_attr(not(feature = "std"), no_std, no_main)] | ||
|
||
#[openbrush::contract] | ||
pub mod my_timelock_controller { | ||
use ink::prelude::vec::Vec; | ||
use openbrush::{ | ||
contracts::{ | ||
nonces, | ||
nonces::{ | ||
NoncesError, | ||
NoncesImpl, | ||
}, | ||
traits::{ | ||
utils::nonces::*, | ||
}, | ||
}, | ||
traits::{ | ||
Storage, | ||
String, | ||
}, | ||
}; | ||
|
||
#[ink(storage)] | ||
#[derive(Default, Storage)] | ||
pub struct Contract { | ||
#[storage_field] | ||
nonces: nonces::Data, | ||
} | ||
|
||
impl Contract { | ||
#[ink(constructor)] | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
#[ink(message)] | ||
pub fn use_nonce(&mut self, account: AccountId) -> Result<u128, NoncesError> { | ||
NoncesImpl::_use_nonce(self, &account) | ||
} | ||
|
||
#[ink(message)] | ||
pub fn use_checked_nonce(&mut self, account: AccountId, nonce: u128) -> Result<u128, NoncesError> { | ||
NoncesImpl::_use_checked_nonce(self, &account, nonce) | ||
} | ||
} | ||
|
||
impl NoncesImpl for Contract {} | ||
|
||
impl Nonces for Contract { | ||
#[ink(message)] | ||
fn nonces(&self, account: AccountId) -> u128 { | ||
NoncesImpl::nonces(self, &account) | ||
} | ||
} | ||
} |
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,33 +1,92 @@ | ||
import { expect, getSigners } from '../helpers' | ||
import { ApiPromise } from '@polkadot/api' | ||
|
||
import Constructor from '../../../typechain-generated/constructors/nonces' | ||
import Contract from '../../../typechain-generated/contracts/nonces' | ||
import BN from "bn.js"; | ||
import {Result} from "@727-ventures/typechain-types"; | ||
|
||
describe('Nonces', function () { | ||
async function setup() { | ||
const api = await ApiPromise.create() | ||
|
||
const signers = getSigners() | ||
const deployer = signers[0] | ||
const bob = signers[1] | ||
|
||
const contractFactory = new Constructor(api, deployer) | ||
const contractAddress = (await contractFactory.new()).address | ||
const contract = new Contract(contractAddress, deployer, api) | ||
|
||
return { | ||
api, | ||
bob, | ||
deployer, | ||
contract, | ||
} | ||
} | ||
|
||
beforeEach(async function () { | ||
// | ||
}) | ||
|
||
it('gets a nonce', async function () { | ||
// | ||
const { | ||
api, | ||
bob, | ||
deployer, | ||
contract, | ||
} = await setup() | ||
const nonce = await contract.query.nonces(bob.address) | ||
expect(await contract.query.nonces(bob.address)).to.have.output(new BN(0)) | ||
await api.disconnect() | ||
}) | ||
|
||
describe('_useNonce', function () { | ||
it('increments a nonce', async function () { | ||
// | ||
const { | ||
api, | ||
bob, | ||
deployer, | ||
contract, | ||
} = await setup() | ||
expect(await contract.query.nonces(bob.address)).to.have.output(new BN(0)) | ||
expect(await contract.query.useNonce(bob.address)).to.have.output(new BN(0)) | ||
expect(await contract.query.useNonce(bob.address)).to.have.output(new BN(1)) | ||
expect(await contract.query.nonces(bob.address)).to.have.output(new BN(2)) | ||
await api.disconnect() | ||
}) | ||
|
||
it('increments only sender\'s nonce', async function () { | ||
// | ||
}) | ||
// it('increments only sender\'s nonce', async function () { | ||
// // | ||
// }) | ||
}) | ||
|
||
describe('_useCheckedNonce', function () { | ||
it('increments a nonce', async function () { | ||
// | ||
const { | ||
api, | ||
bob, | ||
deployer, | ||
contract, | ||
} = await setup() | ||
expect(await contract.query.nonces(bob.address)).to.have.output(new BN(0)) | ||
expect(await contract.query.useCheckedNonce(bob.address, new BN(0))).to.have.output(new BN(0)) | ||
expect(await contract.query.useCheckedNonce(bob.address, new BN(1))).to.have.output(new BN(1)) | ||
}) | ||
|
||
it('increments only sender\'s nonce', async function () { | ||
// | ||
}) | ||
// it('increments only sender\'s nonce', async function () { | ||
// // | ||
// }) | ||
|
||
it('reverts when nonce is not the expected', async function () { | ||
// | ||
const { | ||
api, | ||
bob, | ||
deployer, | ||
contract, | ||
} = await setup() | ||
//todo | ||
}) | ||
}) | ||
}) |
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