receive function

pull/7/head
aniket-engg 5 years ago
parent 74b86f935f
commit 2f6180b0f8
  1. 14
      remix-lib/src/execution/txHelper.js
  2. 4
      remix-lib/src/universalDapp.js
  3. 15
      remix-lib/test/txFormat.js
  4. 10
      remix-lib/test/txHelper.js
  5. 2
      remix-tests/src/types.ts

@ -34,7 +34,7 @@ module.exports = {
},
encodeFunctionId: function (funABI) {
if (funABI.type === 'fallback') return '0x'
if (funABI.type === 'fallback' || funABI.type === 'receive') return '0x'
let abi = new ethers.utils.Interface([funABI])
abi = abi.functions[funABI.name]
return abi.sighash
@ -53,10 +53,10 @@ module.exports = {
return -1
}
// If we reach here, either a and b are both constant or both not; sort by name then
// special case for fallback and constructor
// special case for fallback, receive and constructor function
if (a.type === 'function' && typeof a.name !== 'undefined') {
return a.name.localeCompare(b.name)
} else if (a.type === 'constructor' || a.type === 'fallback') {
} else if (a.type === 'constructor' || a.type === 'fallback' || a.type === 'receive') {
return 1
}
})
@ -124,6 +124,14 @@ module.exports = {
}
},
getReceiveInterface: function (abi) {
for (let i = 0; i < abi.length; i++) {
if (abi[i].type === 'receive') {
return abi[i]
}
}
},
/**
* return the contract obj of the given @arg name. Uses last compilation result.
* return null if not found

@ -253,6 +253,10 @@ module.exports = class UniversalDApp {
return txHelper.getFallbackInterface(contractABI)
}
getReceiveInterface (contractABI) {
return txHelper.getReceiveInterface(contractABI)
}
getInputs (funABI) {
if (!funABI.inputs) {
return ''

@ -243,12 +243,13 @@ function encodeFunctionCallTest (st) {
/* *********************************************************** */
tape('test fallback function', function (t) {
tape('test fallback & receive function', function (t) {
t.test('(fallback)', function (st) {
st.plan(2)
let output = compiler.compile(compilerInput(fallbackFunction))
st.plan(3)
let output = compiler.compile(compilerInput(fallbackAndReceiveFunction))
output = JSON.parse(output)
const contract = output.contracts['test.sol']['fallbackFunctionContract']
const contract = output.contracts['test.sol']['fallbackAndReceiveFunctionContract']
st.equal(txHelper.encodeFunctionId(contract.abi[2]), '0x')
st.equal(txHelper.encodeFunctionId(contract.abi[1]), '0x805da4ad')
st.equal(txHelper.encodeFunctionId(contract.abi[0]), '0x')
})
@ -381,13 +382,15 @@ contract testContractLinkLibrary {
}
}`
const fallbackFunction = `pragma solidity >= 0.5.0 < 0.7.0;
const fallbackAndReceiveFunction = `pragma solidity >= 0.5.0 < 0.7.0;
contract fallbackFunctionContract {
contract fallbackAndReceiveFunctionContract {
function get (uint _p, string memory _o) public {
}
fallback () external {}
receive() payable external{}
}`
const abiEncoderV2 = `pragma experimental ABIEncoderV2;

@ -3,7 +3,7 @@ const tape = require('tape')
const txHelper = require('../src/execution/txHelper')
tape('getFunction', function (st) {
st.plan(5)
st.plan(6)
let fn = txHelper.getFunction(JSON.parse(abi), 'o((address,uint256))')
st.equal(fn.name, 'o')
@ -18,6 +18,9 @@ tape('getFunction', function (st) {
fn = txHelper.getFallbackInterface(JSON.parse(abi))
st.equal(fn.type, 'fallback')
fn = txHelper.getReceiveInterface(JSON.parse(abi))
st.equal(fn.type, 'receive')
})
const abi = `[
@ -143,5 +146,10 @@ const abi = `[
"payable": false,
"stateMutability": "nonpayable",
"type": "fallback"
},
{
"payable": true,
"stateMutability": "payable",
"type": "receive"
}
]`

@ -150,7 +150,7 @@ export type ABIDescription = FunctionDescription | EventDescription
export interface FunctionDescription {
/** Type of the method. default is 'function' */
type?: 'function' | 'constructor' | 'fallback'
type?: 'function' | 'constructor' | 'fallback' | 'receive'
/** The name of the function. Constructor and fallback function never have name */
name?: string
/** List of parameters of the method. Fallback function doesn’t have inputs. */

Loading…
Cancel
Save