refactor(DeployContracts): mint test tokens for local node (#80)

This commit addresses the issue that, when testing the contracts on a
local node, the test (deployer) account does not have any tokens to use
the voting contracts with.

This is fixed by minting tokens as the deployer of the mock SNT
contract.

The commit also adds the expect SNT contract instance as a return value
of the deploy function, ensuring its address is rendered in stdout when
running the script.

Adding it to the returned tuple however caused a "stack too deep" error,
which is why we had to remove one value from the returned tuple.

Since the `DeploymentConfig` contract instance address is irrelevant for actual
deployments, I've removed it from `DeployContracts.run()` and added an
additional function to retrieve it within tests.
This commit is contained in:
r4bbit 2023-10-17 13:28:27 +02:00 committed by GitHub
parent da2810c1cd
commit 9c804dd06f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 31 deletions

View File

@ -12,8 +12,17 @@ import { FeaturedVotingContract } from "../contracts/FeaturedVotingContract.sol"
import { VotingContract } from "../contracts/VotingContract.sol"; import { VotingContract } from "../contracts/VotingContract.sol";
contract DeployContracts is BaseScript { contract DeployContracts is BaseScript {
function run() external returns (Directory, VotingContract, FeaturedVotingContract, DeploymentConfig) { DeploymentConfig internal deploymentConfig;
DeploymentConfig deploymentConfig = new DeploymentConfig(broadcaster);
function getDeploymentConfig() public returns (DeploymentConfig) {
if (address(deploymentConfig) == address(0)) {
deploymentConfig = new DeploymentConfig(broadcaster);
}
return deploymentConfig;
}
function run() external returns (MiniMeToken, Directory, VotingContract, FeaturedVotingContract) {
deploymentConfig = getDeploymentConfig();
( (
uint32 votingLengthInSeconds, uint32 votingLengthInSeconds,
uint32 votingVerificationLength, uint32 votingVerificationLength,
@ -24,17 +33,18 @@ contract DeployContracts is BaseScript {
uint8 featuredPerVotingCount, uint8 featuredPerVotingCount,
address tokenAddress address tokenAddress
) = deploymentConfig.activeNetworkConfig(); ) = deploymentConfig.activeNetworkConfig();
MiniMeToken minimeToken = MiniMeToken(payable(tokenAddress));
vm.startBroadcast(broadcaster); vm.startBroadcast(broadcaster);
VotingContract votingContract = new VotingContract( VotingContract votingContract = new VotingContract(
MiniMeToken(payable(tokenAddress)), minimeToken,
votingLengthInSeconds, votingLengthInSeconds,
votingVerificationLength, votingVerificationLength,
timeBetweenVotingInSeconds timeBetweenVotingInSeconds
); );
FeaturedVotingContract featuredVotingContract = new FeaturedVotingContract( FeaturedVotingContract featuredVotingContract = new FeaturedVotingContract(
MiniMeToken(payable(tokenAddress)), minimeToken,
featuredVotingLength, featuredVotingLength,
featuredVotingVerificationLength, featuredVotingVerificationLength,
cooldownPeriod, cooldownPeriod,
@ -44,6 +54,6 @@ contract DeployContracts is BaseScript {
vm.stopBroadcast(); vm.stopBroadcast();
return (directoryContract, votingContract, featuredVotingContract, deploymentConfig); return (minimeToken, directoryContract, votingContract, featuredVotingContract);
} }
} }

View File

@ -87,6 +87,7 @@ contract DeploymentConfig is Script {
"STT", "STT",
true true
); );
minimeToken.generateTokens(deployer, 100_000_000 ether);
vm.stopBroadcast(); vm.stopBroadcast();
return NetworkConfig({ return NetworkConfig({

View File

@ -18,7 +18,7 @@ contract DirectoryTest is Test {
function setUp() public virtual { function setUp() public virtual {
DeployContracts deployment = new DeployContracts(); DeployContracts deployment = new DeployContracts();
(Directory _directory, VotingContract _votingContract, FeaturedVotingContract _featuredVotingContract,) = (, Directory _directory, VotingContract _votingContract, FeaturedVotingContract _featuredVotingContract) =
deployment.run(); deployment.run();
directory = _directory; directory = _directory;
votingContract = address(_votingContract); votingContract = address(_votingContract);

View File

@ -130,22 +130,16 @@ contract FeaturedVotingContractTest is Test {
function setUp() public virtual { function setUp() public virtual {
DeployContracts deployment = new DeployContracts(); DeployContracts deployment = new DeployContracts();
( (
MiniMeToken _mockSNT,
Directory _directory, Directory _directory,
VotingContract _votingContract, VotingContract _votingContract,
FeaturedVotingContract _featuredVotingContract, FeaturedVotingContract _featuredVotingContract
DeploymentConfig deploymentConfig
) = deployment.run(); ) = deployment.run();
( DeploymentConfig deploymentConfig = deployment.getDeploymentConfig();
,
, (,,, uint32 _featuredVotingLengthInSeconds, uint32 _featuredVotingVerificationLengthInSeconds,,,) =
, deploymentConfig.activeNetworkConfig();
uint32 _featuredVotingLengthInSeconds,
uint32 _featuredVotingVerificationLengthInSeconds,
,
,
address _mockSNT
) = deploymentConfig.activeNetworkConfig();
votingContract = address(_votingContract); votingContract = address(_votingContract);
featuredVotingLengthInSeconds = _featuredVotingLengthInSeconds; featuredVotingLengthInSeconds = _featuredVotingLengthInSeconds;
@ -155,7 +149,7 @@ contract FeaturedVotingContractTest is Test {
featuredVotingContract = _featuredVotingContract; featuredVotingContract = _featuredVotingContract;
directoryContract = _directory; directoryContract = _directory;
mockSNT = MiniMeToken(payable(_mockSNT)); mockSNT = _mockSNT;
deployer = deploymentConfig.deployer(); deployer = deploymentConfig.deployer();
vm.prank(deployer); vm.prank(deployer);

View File

@ -106,18 +106,11 @@ contract VotingContractTest is Test {
function setUp() public virtual { function setUp() public virtual {
DeployContracts deployment = new DeployContracts(); DeployContracts deployment = new DeployContracts();
(Directory _directory, VotingContract _votingContract,, DeploymentConfig deploymentConfig) = deployment.run(); (MiniMeToken _mockSNT, Directory _directory, VotingContract _votingContract,) = deployment.run();
DeploymentConfig deploymentConfig = deployment.getDeploymentConfig();
( (uint32 _votingLengthInSeconds, uint32 _votingVerificationLengthInSeconds, uint32 _timeBetweenVoting,,,,,) =
uint32 _votingLengthInSeconds, deploymentConfig.activeNetworkConfig();
uint32 _votingVerificationLengthInSeconds,
uint32 _timeBetweenVoting,
,
,
,
,
address tokenAddress
) = deploymentConfig.activeNetworkConfig();
timeBetweenVoting = _timeBetweenVoting; timeBetweenVoting = _timeBetweenVoting;
votingContract = _votingContract; votingContract = _votingContract;
@ -125,7 +118,7 @@ contract VotingContractTest is Test {
votingLength = _votingLengthInSeconds; votingLength = _votingLengthInSeconds;
votingVerificationLength = _votingVerificationLengthInSeconds; votingVerificationLength = _votingVerificationLengthInSeconds;
votingWithVerificationLength = votingLength + votingVerificationLength; votingWithVerificationLength = votingLength + votingVerificationLength;
mockSNT = MiniMeToken(payable(tokenAddress)); mockSNT = _mockSNT;
deployer = deploymentConfig.deployer(); deployer = deploymentConfig.deployer();
vm.prank(deployer); vm.prank(deployer);