diff --git a/test/contract/contracts/GLDToken.sol b/test/contract/contracts/GLDToken.sol index 4cd3205f..596baad3 100644 --- a/test/contract/contracts/GLDToken.sol +++ b/test/contract/contracts/GLDToken.sol @@ -4,4 +4,7 @@ contract GLDToken is ERC20 { constructor() ERC20("Gold", "GLD") { _mint(msg.sender, 1000000000000000000000); } + function destroy() public { + selfdestruct(payable(msg.sender)); + } } diff --git a/test/contract/src/index.js b/test/contract/src/index.js index 37639542..b5f865de 100644 --- a/test/contract/src/index.js +++ b/test/contract/src/index.js @@ -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) => { const to = req.query.to; const value = req.query.value; diff --git a/test/helper.go b/test/helper.go index e458bfde..a79b2679 100644 --- a/test/helper.go +++ b/test/helper.go @@ -14,6 +14,12 @@ type ContractDeployed struct { BlockHash string `json:"blockHash"` } +type ContractDestoyed struct { + TransactionHash string `json:"txHash"` + BlockNumber int64 `json:"blockNumber"` + BlockHash string `json:"blockHash"` +} + type Tx struct { From string `json:"from"` To string `json:"to"` @@ -43,6 +49,19 @@ func DeployContract() (*ContractDeployed, error) { 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) { res, err := http.Get(fmt.Sprintf("%s/v1/sendEth?to=%s&value=%s", srvUrl, to, value)) if err != nil { diff --git a/test/integration_test.go b/test/integration_test.go index 43cb8626..38f1d73f 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -391,6 +391,30 @@ var _ = Describe("Integration test", func() { Expect(err).To(MatchError("header not found")) 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() {