Skip to content

Instantly share code, notes, and snippets.

@tin-z
Created January 18, 2023 02:44
Show Gist options
  • Save tin-z/143462696c43d26fc301675ed38c9a40 to your computer and use it in GitHub Desktop.
Save tin-z/143462696c43d26fc301675ed38c9a40 to your computer and use it in GitHub Desktop.
#!/bin/bash
SOLV=0.8.17
folder_t=test_open
if [ "$1" == "make" ]; then
if [ -d $folder_t ] ; then
echo "Folder '$folder_t' already present ...quit"
exit -1
fi
mkdir $folder_t && \
cd $folder_t && \
forge init
forge install brockelmore/forge-std && \
forge install OpenZeppelin/openzeppelin-contracts && \
forge remappings > remappings.txt && \
echo "@openzeppelin/=lib/openzeppelin-contracts/" >> remappings.txt && \
rm test/Counter.t.sol
elif [ "$1" == "clean" ]; then
rm -rf $folder_t
exit 0
else
if [ ! -d $folder_t ] ; then
echo "Folder '$folder_t' NOT preasent ...quit"
exit -1
fi
cd $folder_t
fi
cat >./src/Contract.sol <<EOF
pragma solidity ${SOLV};
contract Tester {
function admin() public {
}
function implementation() public {
}
}
EOF
cat >./test/Contract.t.sol <<EOF
pragma solidity ${SOLV};
import "ds-test/test.sol";
import "forge-std/Vm.sol";
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import "../src/Contract.sol";
contract ContractTest is DSTest {
Vm vm = Vm(HEVM_ADDRESS);
Tester tester_obj;
ProxyAdmin admin;
function setUp() public {
vm.label(address(this), "TestContract");
tester_obj = new Tester();
vm.label(address(tester_obj), "Tester");
admin = new ProxyAdmin();
vm.label(address(admin), "admin");
}
function test_implementation() public {
vm.expectRevert();
admin.getProxyImplementation(
TransparentUpgradeableProxy(
payable(address(tester_obj))
)
);
}
function test_admin() public {
vm.expectRevert();
admin.getProxyAdmin(
TransparentUpgradeableProxy(
payable(address(tester_obj))
)
);
}
}
EOF
forge build && \
forge test -vvvv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment