Skip to content

Commit

Permalink
add test. comparison storages after contract destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
n0cte authored and arijitAD committed Sep 22, 2021
1 parent 3a216b2 commit 1057b00
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/contract/contracts/GLDToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ contract GLDToken is ERC20 {
constructor() ERC20("Gold", "GLD") {
_mint(msg.sender, 1000000000000000000000);
}
function destroy() public {
selfdestruct(payable(msg.sender));
}
}
9 changes: 9 additions & 0 deletions test/contract/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1057b00

Please sign in to comment.