MetaMask / MetaMask/test-dapp

Add buttons to deploy a contract that will always fail when sending a transaction to it

Open
#135 1 comment 0 reactions 1 assignee Claimed by @dragana8 View on GitHub
Dominant language
JavaScript
Stars
642
Forks
369
PR merge metrics
No merged PRs in 30d

Description

We need our test dapp to be able to test error cases. A basic error case that we need to add is a transaction with a smart contract, which will always fail because of a condition internal to the smart contract code.

Here is the code for a smart contract. Transactions sent to this contract will always fail if the value of the transaction is less than 0xfff

```
pragma solidity 0.5.12;

contract MMCheck {

function() external payable {
assert(msg.value > 0xfff);
msg.sender.transfer(msg.value);
}
}
```

The following code would create a transaction to deploy this contract:

```
var mmcheckContract = new web3.eth.Contract([{"payable":true,"stateMutability":"payable","type":"fallback"}]);
var mmcheck = mmcheckContract.deploy({
data: '0x6080604052348015600f57600080fd5b50608b8061001e6000396000f3fe6080604052610fff3411600e57fe5b3373ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f193505050501580156053573d6000803e3d6000fd5b5000fea265627a7a72315820631b0dbb6b871cdbfdec2773af15ebfb8e52c794cf836fe27ec21f1aed17180f64736f6c634300050c0032',
arguments: [
]
}).send({
from: web3.eth.accounts[0],
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
```

We need to add a section to the test dapp that has two buttons, one to deploy this contract and one to send a transaction to it.

**Acceptance criteria**

- add a new section to the "Send Eth" card in the test dapp. Add a new `


` below the current "Contract" section, the section can be very similar to the "Contract" section, except that it should have a new title "Failing Contract", and two buttons: "Deploy Failing Contract" and "Send Failing Transaction"
- clicking the "Deploy Failing Contract" button should call code very similar to the current "Deploy" button code, but instead should deploy the contract data `0x6080604052348015600f57600080fd5b50608b8061001e6000396000f3fe6080604052610fff3411600e57fe5b3373ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f193505050501580156053573d6000803e3d6000fd5b5000fea265627a7a72315820631b0dbb6b871cdbfdec2773af15ebfb8e52c794cf836fe27ec21f1aed17180f64736f6c634300050c0032`
- clicking the "Send Failing Transaction" button should send a transaction with value `0x0` to the address of the new contract (the way that "Deposit" creates a transaction to the address of the contract created by "Deploy")
- if done correctly, the transaction created by "Send Failing Transaction" should show an error message, but you should still be able to submit it. However, after submission, it should fail

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.