Skip to content

Commit

Permalink
Crowdloan with change reward address origin (#873)
Browse files Browse the repository at this point in the history
* Adapt to new wrapped bytes

* Wrapped bytes prefix and postfix

* fix tests

* prettier

* fix mock runtime
  • Loading branch information
girazoki authored Oct 4, 2021
1 parent feab214 commit bddf8d9
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion precompiles/crowdloan-rewards/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use frame_support::{
parameter_types,
traits::{Everything, GenesisBuild, OnFinalize, OnInitialize},
};
use frame_system::RawOrigin;
use frame_system::{EnsureSigned, RawOrigin};
use pallet_evm::{AddressMapping, EnsureAddressNever, EnsureAddressRoot, PrecompileSet};
use serde::{Deserialize, Serialize};
use sp_core::H256;
Expand Down Expand Up @@ -249,6 +249,7 @@ impl pallet_crowdloan_rewards::Config for Test {
type RewardCurrency = Balances;
type RelayChainAccountId = [u8; 32];
type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold;
type RewardAddressChangeOrigin = EnsureSigned<Self::AccountId>;
type VestingBlockNumber = cumulus_primitives_core::relay_chain::BlockNumber;
type VestingBlockProvider =
cumulus_pallet_parachain_system::RelaychainBlockNumberProvider<Self>;
Expand Down
3 changes: 2 additions & 1 deletion runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use xcm_builder::{

use xcm_executor::traits::JustTry;

use frame_system::{EnsureOneOf, EnsureRoot};
use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned};
pub use moonbeam_core_primitives::{
AccountId, AccountIndex, Address, AssetId, Balance, BlockNumber, DigestItem, Hash, Header,
Index, Signature,
Expand Down Expand Up @@ -759,6 +759,7 @@ impl pallet_crowdloan_rewards::Config for Runtime {
type MinimumReward = MinimumReward;
type RewardCurrency = Balances;
type RelayChainAccountId = AccountId32;
type RewardAddressChangeOrigin = EnsureSigned<Self::AccountId>;
type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold;
type VestingBlockNumber = cumulus_primitives_core::relay_chain::BlockNumber;
type VestingBlockProvider =
Expand Down
5 changes: 4 additions & 1 deletion runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,11 @@ fn initialize_crowdloan_address_and_change_with_relay_key_sig() {
let public2 = pair2.public();

// signature is new_account || previous_account
let mut message = AccountId::from(DAVE).encode();
let mut message = pallet_crowdloan_rewards::WRAPPED_BYTES_PREFIX.to_vec();
message.append(&mut AccountId::from(DAVE).encode());
message.append(&mut AccountId::from(CHARLIE).encode());
message.append(&mut pallet_crowdloan_rewards::WRAPPED_BYTES_POSTFIX.to_vec());

let signature1 = pair1.sign(&message);
let signature2 = pair2.sign(&message);

Expand Down
3 changes: 2 additions & 1 deletion runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use frame_support::{
},
PalletId,
};
use frame_system::{EnsureOneOf, EnsureRoot};
use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned};
pub use moonbeam_core_primitives::{
AccountId, AccountIndex, Address, Balance, BlockNumber, DigestItem, Hash, Header, Index,
Signature,
Expand Down Expand Up @@ -707,6 +707,7 @@ impl pallet_crowdloan_rewards::Config for Runtime {
type MinimumReward = MinimumReward;
type RewardCurrency = Balances;
type RelayChainAccountId = AccountId32;
type RewardAddressChangeOrigin = EnsureSigned<Self::AccountId>;
type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold;
type VestingBlockNumber = cumulus_primitives_core::relay_chain::BlockNumber;
type VestingBlockProvider =
Expand Down
4 changes: 3 additions & 1 deletion runtime/moonbeam/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,10 @@ fn initialize_crowdloan_address_and_change_with_relay_key_sig() {
let public2 = pair2.public();

// signature is new_account || previous_account
let mut message = AccountId::from(DAVE).encode();
let mut message = pallet_crowdloan_rewards::WRAPPED_BYTES_PREFIX.to_vec();
message.append(&mut AccountId::from(DAVE).encode());
message.append(&mut AccountId::from(CHARLIE).encode());
message.append(&mut pallet_crowdloan_rewards::WRAPPED_BYTES_POSTFIX.to_vec());
let signature1 = pair1.sign(&message);
let signature2 = pair2.sign(&message);

Expand Down
3 changes: 2 additions & 1 deletion runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use frame_support::{
},
PalletId,
};
use frame_system::{EnsureOneOf, EnsureRoot};
use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned};
pub use moonbeam_core_primitives::{
AccountId, AccountIndex, Address, Balance, BlockNumber, DigestItem, Hash, Header, Index,
Signature,
Expand Down Expand Up @@ -698,6 +698,7 @@ impl pallet_crowdloan_rewards::Config for Runtime {
type MinimumReward = MinimumReward;
type RewardCurrency = Balances;
type RelayChainAccountId = AccountId32;
type RewardAddressChangeOrigin = EnsureSigned<Self::AccountId>;
type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold;
type VestingBlockNumber = cumulus_primitives_core::relay_chain::BlockNumber;
type VestingBlockProvider =
Expand Down
4 changes: 3 additions & 1 deletion runtime/moonriver/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,10 @@ fn initialize_crowdloan_address_and_change_with_relay_key_sig() {
let public2 = pair2.public();

// signature is new_account || previous_account
let mut message = AccountId::from(DAVE).encode();
let mut message = pallet_crowdloan_rewards::WRAPPED_BYTES_PREFIX.to_vec();
message.append(&mut AccountId::from(DAVE).encode());
message.append(&mut AccountId::from(CHARLIE).encode());
message.append(&mut pallet_crowdloan_rewards::WRAPPED_BYTES_POSTFIX.to_vec());
let signature1 = pair1.sign(&message);
let signature2 = pair2.sign(&message);

Expand Down
9 changes: 7 additions & 2 deletions tests/tests/test-crowdloan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { KeyringPair } from "@polkadot/keyring/types";
import { expect } from "chai";
import Web3 from "web3";
import { Account } from "web3-core";
import { formatBalance } from "@polkadot/util";
import { formatBalance, stringToU8a } from "@polkadot/util";
import type { SubmittableExtrinsic } from "@polkadot/api/promise/types";
import { blake2AsHex, randomAsHex } from "@polkadot/util-crypto";

Expand Down Expand Up @@ -823,7 +823,12 @@ describeDevMoonbeam("Crowdloan", (context) => {
).toHuman() as any
).to.be.null;

let message = new Uint8Array([...toAssociateAccount.addressRaw, ...firstAccount.addressRaw]);
let message = new Uint8Array([
...stringToU8a("<Bytes>"),
...toAssociateAccount.addressRaw,
...firstAccount.addressRaw,
...stringToU8a("</Bytes>"),
]);

// Construct the signatures
let signature1 = {};
Expand Down

0 comments on commit bddf8d9

Please sign in to comment.