add test. comparison storages after contract destruction

This commit is contained in:
n0cte 2021-09-06 17:44:06 +03:00 committed by Arijit Das
parent 3a216b2ca3
commit 1057b001f1
4 changed files with 55 additions and 0 deletions

View File

@ -4,4 +4,7 @@ contract GLDToken is ERC20 {
constructor() ERC20("Gold", "GLD") { constructor() ERC20("Gold", "GLD") {
_mint(msg.sender, 1000000000000000000000); _mint(msg.sender, 1000000000000000000000);
} }
function destroy() public {
selfdestruct(payable(msg.sender));
}
} }

View File

@ -22,6 +22,15 @@ fastify.get('/v1/deployContract', async (req, reply) => {
} }
}); });
fastify.get('/v1/destoyContract', async (req, reply) => {
const addr = req.query.addr;
const Token = await hre.ethers.getContractFactory("GLDToken");
const token = await Token.attach(addr);
return token.destroy();
})
fastify.get('/v1/sendEth', async (req, reply) => { fastify.get('/v1/sendEth', async (req, reply) => {
const to = req.query.to; const to = req.query.to;
const value = req.query.value; const value = req.query.value;

View File

@ -14,6 +14,12 @@ type ContractDeployed struct {
BlockHash string `json:"blockHash"` BlockHash string `json:"blockHash"`
} }
type ContractDestoyed struct {
TransactionHash string `json:"txHash"`
BlockNumber int64 `json:"blockNumber"`
BlockHash string `json:"blockHash"`
}
type Tx struct { type Tx struct {
From string `json:"from"` From string `json:"from"`
To string `json:"to"` To string `json:"to"`
@ -43,6 +49,19 @@ func DeployContract() (*ContractDeployed, error) {
return &contract, nil return &contract, nil
} }
func DestoyContract(addr string) (*ContractDestoyed, error) {
res, err := http.Get(fmt.Sprintf("%s/v1/destoyContract?addr=%s", srvUrl, addr))
if err != nil {
return nil, err
}
defer res.Body.Close()
var data ContractDestoyed
decoder := json.NewDecoder(res.Body)
return &data, decoder.Decode(&data)
}
func SendEth(to string, value string) (*Tx, error) { func SendEth(to string, value string) (*Tx, error) {
res, err := http.Get(fmt.Sprintf("%s/v1/sendEth?to=%s&value=%s", srvUrl, to, value)) res, err := http.Get(fmt.Sprintf("%s/v1/sendEth?to=%s&value=%s", srvUrl, to, value))
if err != nil { if err != nil {

View File

@ -391,6 +391,30 @@ var _ = Describe("Integration test", func() {
Expect(err).To(MatchError("header not found")) Expect(err).To(MatchError("header not found"))
Expect(gethStorage).To(Equal(ipldStorage)) Expect(gethStorage).To(Equal(ipldStorage))
}) })
It("get storage after selfdestruct", func() {
totalSupplyIndex := "0x2"
zeroHash := make([]byte, 32)
tx, err := integration.DestoyContract(contract.Address)
Expect(err).ToNot(HaveOccurred())
gethStorage1, err := gethClient.StorageAt(ctx, common.HexToAddress(contract.Address), common.HexToHash(totalSupplyIndex), big.NewInt(tx.BlockNumber-1))
Expect(err).ToNot(HaveOccurred())
gethStorage2, err := gethClient.StorageAt(ctx, common.HexToAddress(contract.Address), common.HexToHash(totalSupplyIndex), big.NewInt(tx.BlockNumber))
Expect(err).ToNot(HaveOccurred())
Expect(gethStorage1).NotTo(Equal(gethStorage2))
Expect(gethStorage2).To(Equal(zeroHash))
ipldStorage1, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract.Address), common.HexToHash(totalSupplyIndex), big.NewInt(tx.BlockNumber-1))
Expect(err).ToNot(HaveOccurred())
ipldStorage2, err := ipldClient.StorageAt(ctx, common.HexToAddress(contract.Address), common.HexToHash(totalSupplyIndex), big.NewInt(tx.BlockNumber))
Expect(err).ToNot(HaveOccurred())
Expect(ipldStorage1).To(Equal(gethStorage1))
Expect(ipldStorage2).To(Equal(gethStorage2))
})
}) })
Describe("eth call", func() { Describe("eth call", func() {