Skip to content

Commit

Permalink
chore: increase coverage & refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
fedealconada committed Jan 27, 2024
1 parent ccdf17a commit 9cd3cee
Show file tree
Hide file tree
Showing 25 changed files with 661 additions and 525 deletions.
20 changes: 10 additions & 10 deletions script/deploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract KintoInitialDeployScript is Create2Helper, ArtifactsReader {
SponsorPaymaster _sponsorPaymasterImpl;
SponsorPaymaster _sponsorPaymaster;
KintoID _implementation;
KintoID _kintoIDv1;
KintoID _kintoID;
UUPSProxy _proxy;
IKintoWallet _walletImpl;
IKintoWallet _kintoWalletv1;
Expand Down Expand Up @@ -62,17 +62,17 @@ contract KintoInitialDeployScript is Create2Helper, ArtifactsReader {
if (isContract(kintoProxyAddr)) {
_proxy = UUPSProxy(payable(kintoProxyAddr));
console.log("Already deployed Kinto ID proxy at", address(kintoProxyAddr));
_kintoIDv1 = KintoID(address(_proxy));
_kintoID = KintoID(address(_proxy));
} else {
// deploy proxy contract and point it to implementation
_proxy = new UUPSProxy{salt: 0}(address(_implementation), "");
// wrap in ABI to support easier calls
_kintoIDv1 = KintoID(address(_proxy));
console.log("Kinto ID proxy deployed at ", address(_kintoIDv1));
_kintoID = KintoID(address(_proxy));
console.log("Kinto ID proxy deployed at ", address(_kintoID));
// Initialize proxy
_kintoIDv1.initialize();
_kintoID.initialize();
}
_kintoIDv1 = KintoID(address(_proxy));
_kintoID = KintoID(address(_proxy));

// Entry Point
address entryPointAddr = computeAddress(1, abi.encodePacked(type(EntryPoint).creationCode));
Expand All @@ -88,14 +88,14 @@ contract KintoInitialDeployScript is Create2Helper, ArtifactsReader {

// Wallet Implementation for the beacon
address walletImplementationAddr = computeAddress(
0, abi.encodePacked(type(KintoWallet).creationCode, abi.encode(address(_entryPoint), address(_kintoIDv1)))
0, abi.encodePacked(type(KintoWallet).creationCode, abi.encode(address(_entryPoint), address(_kintoID)))
);
if (isContract(walletImplementationAddr)) {
_walletImpl = KintoWallet(payable(walletImplementationAddr));
console.log("Wallet Implementation already deployed at", address(walletImplementationAddr));
} else {
// Deploy Wallet Implementation
_walletImpl = new KintoWallet{salt: 0}(_entryPoint, _kintoIDv1, IKintoAppRegistry(address(0)));
_walletImpl = new KintoWallet{salt: 0}(_entryPoint, _kintoID, IKintoAppRegistry(address(0)));
console.log("Wallet Implementation deployed at", address(_walletImpl));
}

Expand Down Expand Up @@ -129,7 +129,7 @@ contract KintoInitialDeployScript is Create2Helper, ArtifactsReader {
_walletFactory = KintoWalletFactory(address(_proxy));
console.log("Wallet Factory proxy deployed at ", address(_walletFactory));
// Initialize proxy
_walletFactory.initialize(_kintoIDv1);
_walletFactory.initialize(_kintoID);
}

address walletFactory = _entryPoint.walletFactory();
Expand Down Expand Up @@ -207,7 +207,7 @@ contract KintoInitialDeployScript is Create2Helper, ArtifactsReader {

// Writes the addresses to a file
vm.writeFile(_getAddressesFile(), "{\n");
vm.writeLine(_getAddressesFile(), string.concat('"KintoID": "', vm.toString(address(_kintoIDv1)), '",'));
vm.writeLine(_getAddressesFile(), string.concat('"KintoID": "', vm.toString(address(_kintoID)), '",'));
vm.writeLine(
_getAddressesFile(), string.concat('"KintoID-impl": "', vm.toString(address(_implementation)), '",')
);
Expand Down
23 changes: 12 additions & 11 deletions script/migrations/03-mint_nft_admin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,33 @@ import "forge-std/console.sol";
contract KintoMigration3DeployScript is Create2Helper, KYCSignature, ArtifactsReader {
using ECDSAUpgradeable for bytes32;

KintoID _kintoIDv1;
KintoID _kintoID;

function setUp() public {}

function run() public {
console.log("RUNNING ON CHAIN WITH ID", vm.toString(block.chainid));
// If not using ledger, replace

// if not using ledger, replace
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.rememberKey(deployerPrivateKey);
vm.startBroadcast(deployerPrivateKey);

console.log("Executing with address", deployer);
// vm.startBroadcast();
address walletFactoryAddr = _getChainDeployment("KintoWalletFactory");
if (walletFactoryAddr == address(0)) {
console.log("Need to execute main deploy script first", walletFactoryAddr);
return;
}
// Mint an nft to the owner
_kintoIDv1 = KintoID(_getChainDeployment("KintoID"));

// mint an nft to the owner
_kintoID = KintoID(_getChainDeployment("KintoID"));
IKintoID.SignatureData memory sigdata =
_auxCreateSignature(_kintoIDv1, deployer, deployer, deployerPrivateKey, block.timestamp + 1000);
vm.stopBroadcast();
vm.startBroadcast();
_auxCreateSignature(_kintoID, deployer, deployerPrivateKey, block.timestamp + 1000);

uint16[] memory traits = new uint16[](1);
traits[0] = 0; // ADMIN
_kintoIDv1.mintIndividualKyc(sigdata, traits);
vm.stopBroadcast();

vm.broadcast();
_kintoID.mintIndividualKyc(sigdata, traits);
}
}
2 changes: 1 addition & 1 deletion script/migrations/04-deploy_admin_wallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract KintoMigration4DeployScript is Create2Helper, ArtifactsReader {

KintoWalletFactory _walletFactory;
KintoWallet _kintoWalletv1;
KintoID _kintoIDv1;
KintoID _kintoID;
UUPSProxy _proxy;

function setUp() public {}
Expand Down
2 changes: 1 addition & 1 deletion script/migrations/12-create_engen_app.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import "../../test/helpers/UserOp.sol";
contract KintoMigration12DeployScript is ArtifactsReader, UserOp {
KintoWalletFactory _walletFactory;
KintoWallet _kintoWalletv1;
KintoID _kintoIDv1;
KintoID _kintoID;
UUPSProxy _proxy;

function setUp() public {}
Expand Down
2 changes: 1 addition & 1 deletion script/test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract KintoDeployTestWalletScript is AASetup, KYCSignature {
vm.startBroadcast(deployerPrivateKey);
if (!_kintoID.isKYC(recipientWallet)) {
IKintoID.SignatureData memory sigdata =
_auxCreateSignature(_kintoID, recipientWallet, recipientWallet, recipientKey, block.timestamp + 1000);
_auxCreateSignature(_kintoID, recipientWallet, recipientKey, block.timestamp + 1000);
uint16[] memory traits = new uint16[](0);
_kintoID.mintIndividualKyc(sigdata, traits);
}
Expand Down
4 changes: 2 additions & 2 deletions script/upgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ contract KintoWalletFactoryUpgradeScript is ArtifactsReader {
}

contract KintoWalletVTest is KintoWallet {
constructor(IEntryPoint _entryPoint, IKintoID _kintoIDv1, IKintoAppRegistry _kintoApp)
KintoWallet(_entryPoint, _kintoIDv1, _kintoApp)
constructor(IEntryPoint _entryPoint, IKintoID _kintoID, IKintoAppRegistry _kintoApp)
KintoWallet(_entryPoint, _kintoID, _kintoApp)
{}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract CounterInitializable is Initializable, OwnableUpgradeable, UUPSUpgradeable {
contract InitializableCounter is Initializable, OwnableUpgradeable, UUPSUpgradeable {
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
Expand Down
60 changes: 27 additions & 33 deletions test/DeployTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,41 @@ pragma solidity ^0.8.18;
import "forge-std/Test.sol";
import "forge-std/console.sol";

import "../src/sample/CounterInitializable.sol";
import {OwnableCounter as Counter} from "../src/sample/OwnableCounter.sol";

import "./helpers/UserOp.sol";
import "../src/sample/OwnableCounter.sol";
import "../src/sample/InitializableCounter.sol";
import "./SharedSetup.t.sol";
import "./helpers/UUPSProxy.sol";
import {AATestScaffolding} from "./helpers/AATestScaffolding.sol";

contract DeveloperDeployTest is UserOp, AATestScaffolding {
uint256 _chainID = 1;

UUPSProxy _proxyc;
Counter _counter;
CounterInitializable _counterInit;
contract DeveloperDeployTest is SharedSetup {
OwnableCounter _ownableCounter;
InitializableCounter _initializableCounter;

function setUp() public {
vm.chainId(_chainID);
vm.startPrank(address(1));
_owner.transfer(1e18);
vm.stopPrank();
deployAAScaffolding(_owner, 1, _kycProvider, _recoverer);
vm.startPrank(_owner);
function setUp() public override {
super.setUp();

address created =
_walletFactory.deployContract(_owner, 0, abi.encodePacked(type(Counter).creationCode), bytes32(0));
_counter = Counter(created);
// deploy ownable counter
vm.prank(_owner);
_ownableCounter = OwnableCounter(
_walletFactory.deployContract(_owner, 0, abi.encodePacked(type(OwnableCounter).creationCode), bytes32(0))
);

created = _walletFactory.deployContract(
_owner, 0, abi.encodePacked(type(CounterInitializable).creationCode), bytes32(0)
// deploy initialisable counter
vm.prank(_owner);
address _implementation = _walletFactory.deployContract(
_owner, 0, abi.encodePacked(type(InitializableCounter).creationCode), bytes32(0)
);

// deploy _proxy contract and point it to _implementation
_proxyc = new UUPSProxy{salt: 0}(address(created), "");
// wrap in ABI to support easier calls
_counterInit = CounterInitializable(address(_proxyc));
// Initialize proxy
_counterInit.initialize(_user2);
vm.stopPrank();
// deploy proxy contract for initialisable counter and point it to _implementation
UUPSProxy _proxy = new UUPSProxy{salt: 0}(address(_implementation), "");

// initialize proxy
_initializableCounter = InitializableCounter(address(_proxy));
vm.prank(_owner);
_initializableCounter.initialize(_user2);
}

function testUp() public {
assertEq(address(_owner), _counter.owner());
assertEq(_user2, _counterInit.owner());
function testUp() public override {
assertEq(address(_owner), _ownableCounter.owner());
assertEq(_user2, _initializableCounter.owner());
}
}
2 changes: 1 addition & 1 deletion test/ETHPriceIsRight.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract ETHPriceIsRightTest is Test {
assertEq(_priceIsRight.maxGuess(), 0);
}

// Upgrade Tests
// Upgrade tests

function testAnyoneCanEnterGuessBeforeEnd() public {
vm.startPrank(_user);
Expand Down
Loading

0 comments on commit 9cd3cee

Please sign in to comment.