Skip to content

Instantly share code, notes, and snippets.

@tomusdrw
Created September 25, 2020 12:16
Show Gist options
  • Save tomusdrw/630af955a454aca05d389f318c354f5f to your computer and use it in GitHub Desktop.
Save tomusdrw/630af955a454aca05d389f318c354f5f to your computer and use it in GitHub Desktop.
// creating a state dump file (one time job), later on it's uploaded to S3 or something.
// We could build an API service with an archive node that can compute state dumps at any block you request and then cache them.
remote_externalities::Builder::new()
.module("PhragmenElection")
.uri(URI.to_owned())
.at(now)
.dump_to_file(format!("PhragmenElection-at-{}-polkadot.statedump", now, URI))
.await;
/// actual test (can be re-run as many times you want, without the need to access an actual node)
remote_externalities::Builder::new()
// this reads a local cached file (or requests from a S3 bucket if not found)
.from_state_dump("./PhragmenElection-at-<hash>-polkadot.statedump")
.build_async()
.await
.execute_with(|| {
let random_voter = <StorageKeyIterator<AccountId, (Balance, Vec<AccountId>), frame_support::Twox64Concat>>::new(
b"PhragmenElection",
b"Voting",
).skip(5)
.take(1)
.map(|(voter, (stake, votes))| (voter, stake, votes))
.collect::<Vec<_>>();
let (random_voter, stake, votes) = random_voter.first().unwrap();
pallet_elections_phragmen::migrations::migrate_to_recorded_deposit::<Runtime>(1000_000);
let voting = <Voting<Runtime>>::get(random_voter);
assert_eq!(&voting.votes, votes);
assert_eq!(voting.stake, *stake);
assert_eq!(voting.deposit, 1000_000);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment