mirror of openzeppelin-contracts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openzeppelin-contracts/test/GSN/GSNRecipientSignature.test.js

91 lines
3.4 KiB

const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const { expectEvent, expectRevert, constants } = require('@openzeppelin/test-helpers');
Initial GSN support (beta) (#1844) * Add base Context contract * Add GSNContext and tests * Add RelayHub deployment to tests * Add RelayProvider integration, complete GSNContext tests * Switch dependency to openzeppelin-gsn-provider * Add default txfee to provider * Add basic signing recipient * Sign more values * Add comment clarifying RelayHub's msg.data * Make context constructors internal * Rename SigningRecipient to GSNRecipientSignedData * Add ERC20Charge recipients * Harcode RelayHub address into GSNContext * Fix Solidity linter errors * Run server from binary, use gsn-helpers to fund it * Migrate to published @openzeppelin/gsn-helpers * Silence false-positive compiler warning * Use GSN helper assertions * Rename meta-tx to gsn, take out of drafts * Merge ERC20 charge recipients into a single one * Rename GSNRecipients to Bouncers * Add GSNBouncerUtils to decouple the bouncers from GSNRecipient * Add _upgradeRelayHub * Store RelayHub address using unstructored storage * Add IRelayHub * Add _withdrawDeposits to GSNRecipient * Add relayHub version to recipient * Make _acceptRelayedCall and _declineRelayedCall easier to use * Rename GSNBouncerUtils to GSNBouncerBase, make it IRelayRecipient * Improve GSNBouncerBase, make pre and post sender-protected and optional * Fix GSNBouncerERC20Fee, add tests * Add missing GSNBouncerSignature test * Override transferFrom in __unstable__ERC20PrimaryAdmin * Fix gsn dependencies in package.json * Rhub address slot reduced by 1 * Rename relay hub changed event * Use released gsn-provider * Run relayer with short sleep of 1s instead of 100ms * update package-lock.json * clear circle cache * use optimized gsn-provider * update to latest @openzeppelin/gsn-provider * replace with gsn dev provider * remove relay server * rename arguments in approveFunction * fix GSNBouncerSignature test * change gsn txfee * initialize development provider only once * update RelayHub interface * adapt to new IRelayHub.withdraw * update @openzeppelin/gsn-helpers * update relayhub singleton address * fix helper name * set up gsn provider for coverage too * lint * Revert "set up gsn provider for coverage too" This reverts commit 8a7b5be5f942002710cba148f249cb888ee8e373. * remove unused code * add gsn provider to coverage * move truffle contract options back out * increase gas limit for coverage * remove unreachable code * add more gas for GSNContext test * fix test suite name * rename GSNBouncerBase internal API * remove onlyRelayHub modifier * add explicit inheritance * remove redundant event * update name of bouncers error codes enums * add basic docs page for gsn contracts * make gsn directory all caps * add changelog entry * lint * enable test run to fail in coverage
6 years ago
const gsn = require('@openzeppelin/gsn-helpers');
const { fixSignature } = require('../helpers/sign');
const { utils: { toBN } } = require('web3');
const { ZERO_ADDRESS } = constants;
Initial GSN support (beta) (#1844) * Add base Context contract * Add GSNContext and tests * Add RelayHub deployment to tests * Add RelayProvider integration, complete GSNContext tests * Switch dependency to openzeppelin-gsn-provider * Add default txfee to provider * Add basic signing recipient * Sign more values * Add comment clarifying RelayHub's msg.data * Make context constructors internal * Rename SigningRecipient to GSNRecipientSignedData * Add ERC20Charge recipients * Harcode RelayHub address into GSNContext * Fix Solidity linter errors * Run server from binary, use gsn-helpers to fund it * Migrate to published @openzeppelin/gsn-helpers * Silence false-positive compiler warning * Use GSN helper assertions * Rename meta-tx to gsn, take out of drafts * Merge ERC20 charge recipients into a single one * Rename GSNRecipients to Bouncers * Add GSNBouncerUtils to decouple the bouncers from GSNRecipient * Add _upgradeRelayHub * Store RelayHub address using unstructored storage * Add IRelayHub * Add _withdrawDeposits to GSNRecipient * Add relayHub version to recipient * Make _acceptRelayedCall and _declineRelayedCall easier to use * Rename GSNBouncerUtils to GSNBouncerBase, make it IRelayRecipient * Improve GSNBouncerBase, make pre and post sender-protected and optional * Fix GSNBouncerERC20Fee, add tests * Add missing GSNBouncerSignature test * Override transferFrom in __unstable__ERC20PrimaryAdmin * Fix gsn dependencies in package.json * Rhub address slot reduced by 1 * Rename relay hub changed event * Use released gsn-provider * Run relayer with short sleep of 1s instead of 100ms * update package-lock.json * clear circle cache * use optimized gsn-provider * update to latest @openzeppelin/gsn-provider * replace with gsn dev provider * remove relay server * rename arguments in approveFunction * fix GSNBouncerSignature test * change gsn txfee * initialize development provider only once * update RelayHub interface * adapt to new IRelayHub.withdraw * update @openzeppelin/gsn-helpers * update relayhub singleton address * fix helper name * set up gsn provider for coverage too * lint * Revert "set up gsn provider for coverage too" This reverts commit 8a7b5be5f942002710cba148f249cb888ee8e373. * remove unused code * add gsn provider to coverage * move truffle contract options back out * increase gas limit for coverage * remove unreachable code * add more gas for GSNContext test * fix test suite name * rename GSNBouncerBase internal API * remove onlyRelayHub modifier * add explicit inheritance * remove redundant event * update name of bouncers error codes enums * add basic docs page for gsn contracts * make gsn directory all caps * add changelog entry * lint * enable test run to fail in coverage
6 years ago
const GSNRecipientSignatureMock = contract.fromArtifact('GSNRecipientSignatureMock');
describe('GSNRecipientSignature', function () {
const [ signer, other ] = accounts;
Initial GSN support (beta) (#1844) * Add base Context contract * Add GSNContext and tests * Add RelayHub deployment to tests * Add RelayProvider integration, complete GSNContext tests * Switch dependency to openzeppelin-gsn-provider * Add default txfee to provider * Add basic signing recipient * Sign more values * Add comment clarifying RelayHub's msg.data * Make context constructors internal * Rename SigningRecipient to GSNRecipientSignedData * Add ERC20Charge recipients * Harcode RelayHub address into GSNContext * Fix Solidity linter errors * Run server from binary, use gsn-helpers to fund it * Migrate to published @openzeppelin/gsn-helpers * Silence false-positive compiler warning * Use GSN helper assertions * Rename meta-tx to gsn, take out of drafts * Merge ERC20 charge recipients into a single one * Rename GSNRecipients to Bouncers * Add GSNBouncerUtils to decouple the bouncers from GSNRecipient * Add _upgradeRelayHub * Store RelayHub address using unstructored storage * Add IRelayHub * Add _withdrawDeposits to GSNRecipient * Add relayHub version to recipient * Make _acceptRelayedCall and _declineRelayedCall easier to use * Rename GSNBouncerUtils to GSNBouncerBase, make it IRelayRecipient * Improve GSNBouncerBase, make pre and post sender-protected and optional * Fix GSNBouncerERC20Fee, add tests * Add missing GSNBouncerSignature test * Override transferFrom in __unstable__ERC20PrimaryAdmin * Fix gsn dependencies in package.json * Rhub address slot reduced by 1 * Rename relay hub changed event * Use released gsn-provider * Run relayer with short sleep of 1s instead of 100ms * update package-lock.json * clear circle cache * use optimized gsn-provider * update to latest @openzeppelin/gsn-provider * replace with gsn dev provider * remove relay server * rename arguments in approveFunction * fix GSNBouncerSignature test * change gsn txfee * initialize development provider only once * update RelayHub interface * adapt to new IRelayHub.withdraw * update @openzeppelin/gsn-helpers * update relayhub singleton address * fix helper name * set up gsn provider for coverage too * lint * Revert "set up gsn provider for coverage too" This reverts commit 8a7b5be5f942002710cba148f249cb888ee8e373. * remove unused code * add gsn provider to coverage * move truffle contract options back out * increase gas limit for coverage * remove unreachable code * add more gas for GSNContext test * fix test suite name * rename GSNBouncerBase internal API * remove onlyRelayHub modifier * add explicit inheritance * remove redundant event * update name of bouncers error codes enums * add basic docs page for gsn contracts * make gsn directory all caps * add changelog entry * lint * enable test run to fail in coverage
6 years ago
beforeEach(async function () {
this.recipient = await GSNRecipientSignatureMock.new(signer);
Initial GSN support (beta) (#1844) * Add base Context contract * Add GSNContext and tests * Add RelayHub deployment to tests * Add RelayProvider integration, complete GSNContext tests * Switch dependency to openzeppelin-gsn-provider * Add default txfee to provider * Add basic signing recipient * Sign more values * Add comment clarifying RelayHub's msg.data * Make context constructors internal * Rename SigningRecipient to GSNRecipientSignedData * Add ERC20Charge recipients * Harcode RelayHub address into GSNContext * Fix Solidity linter errors * Run server from binary, use gsn-helpers to fund it * Migrate to published @openzeppelin/gsn-helpers * Silence false-positive compiler warning * Use GSN helper assertions * Rename meta-tx to gsn, take out of drafts * Merge ERC20 charge recipients into a single one * Rename GSNRecipients to Bouncers * Add GSNBouncerUtils to decouple the bouncers from GSNRecipient * Add _upgradeRelayHub * Store RelayHub address using unstructored storage * Add IRelayHub * Add _withdrawDeposits to GSNRecipient * Add relayHub version to recipient * Make _acceptRelayedCall and _declineRelayedCall easier to use * Rename GSNBouncerUtils to GSNBouncerBase, make it IRelayRecipient * Improve GSNBouncerBase, make pre and post sender-protected and optional * Fix GSNBouncerERC20Fee, add tests * Add missing GSNBouncerSignature test * Override transferFrom in __unstable__ERC20PrimaryAdmin * Fix gsn dependencies in package.json * Rhub address slot reduced by 1 * Rename relay hub changed event * Use released gsn-provider * Run relayer with short sleep of 1s instead of 100ms * update package-lock.json * clear circle cache * use optimized gsn-provider * update to latest @openzeppelin/gsn-provider * replace with gsn dev provider * remove relay server * rename arguments in approveFunction * fix GSNBouncerSignature test * change gsn txfee * initialize development provider only once * update RelayHub interface * adapt to new IRelayHub.withdraw * update @openzeppelin/gsn-helpers * update relayhub singleton address * fix helper name * set up gsn provider for coverage too * lint * Revert "set up gsn provider for coverage too" This reverts commit 8a7b5be5f942002710cba148f249cb888ee8e373. * remove unused code * add gsn provider to coverage * move truffle contract options back out * increase gas limit for coverage * remove unreachable code * add more gas for GSNContext test * fix test suite name * rename GSNBouncerBase internal API * remove onlyRelayHub modifier * add explicit inheritance * remove redundant event * update name of bouncers error codes enums * add basic docs page for gsn contracts * make gsn directory all caps * add changelog entry * lint * enable test run to fail in coverage
6 years ago
});
context('when called directly', function () {
it('mock function can be called', async function () {
const { logs } = await this.recipient.mockFunction();
expectEvent.inLogs(logs, 'MockFunctionCalled');
});
});
context('when constructor is called with a zero address', function () {
it('fails when constructor called with a zero address', async function () {
await expectRevert(
GSNRecipientSignatureMock.new(
ZERO_ADDRESS
),
'GSNRecipientSignature: trusted signer is the zero address'
);
});
});
Initial GSN support (beta) (#1844) * Add base Context contract * Add GSNContext and tests * Add RelayHub deployment to tests * Add RelayProvider integration, complete GSNContext tests * Switch dependency to openzeppelin-gsn-provider * Add default txfee to provider * Add basic signing recipient * Sign more values * Add comment clarifying RelayHub's msg.data * Make context constructors internal * Rename SigningRecipient to GSNRecipientSignedData * Add ERC20Charge recipients * Harcode RelayHub address into GSNContext * Fix Solidity linter errors * Run server from binary, use gsn-helpers to fund it * Migrate to published @openzeppelin/gsn-helpers * Silence false-positive compiler warning * Use GSN helper assertions * Rename meta-tx to gsn, take out of drafts * Merge ERC20 charge recipients into a single one * Rename GSNRecipients to Bouncers * Add GSNBouncerUtils to decouple the bouncers from GSNRecipient * Add _upgradeRelayHub * Store RelayHub address using unstructored storage * Add IRelayHub * Add _withdrawDeposits to GSNRecipient * Add relayHub version to recipient * Make _acceptRelayedCall and _declineRelayedCall easier to use * Rename GSNBouncerUtils to GSNBouncerBase, make it IRelayRecipient * Improve GSNBouncerBase, make pre and post sender-protected and optional * Fix GSNBouncerERC20Fee, add tests * Add missing GSNBouncerSignature test * Override transferFrom in __unstable__ERC20PrimaryAdmin * Fix gsn dependencies in package.json * Rhub address slot reduced by 1 * Rename relay hub changed event * Use released gsn-provider * Run relayer with short sleep of 1s instead of 100ms * update package-lock.json * clear circle cache * use optimized gsn-provider * update to latest @openzeppelin/gsn-provider * replace with gsn dev provider * remove relay server * rename arguments in approveFunction * fix GSNBouncerSignature test * change gsn txfee * initialize development provider only once * update RelayHub interface * adapt to new IRelayHub.withdraw * update @openzeppelin/gsn-helpers * update relayhub singleton address * fix helper name * set up gsn provider for coverage too * lint * Revert "set up gsn provider for coverage too" This reverts commit 8a7b5be5f942002710cba148f249cb888ee8e373. * remove unused code * add gsn provider to coverage * move truffle contract options back out * increase gas limit for coverage * remove unreachable code * add more gas for GSNContext test * fix test suite name * rename GSNBouncerBase internal API * remove onlyRelayHub modifier * add explicit inheritance * remove redundant event * update name of bouncers error codes enums * add basic docs page for gsn contracts * make gsn directory all caps * add changelog entry * lint * enable test run to fail in coverage
6 years ago
context('when relay-called', function () {
beforeEach(async function () {
await gsn.fundRecipient(web3, { recipient: this.recipient.address });
});
it('rejects unsigned relay requests', async function () {
await gsn.expectError(this.recipient.mockFunction({ value: 0, useGSN: true }));
});
it('rejects relay requests where some parameters are signed', async function () {
const approveFunction = async (data) =>
fixSignature(
await web3.eth.sign(
web3.utils.soliditySha3(
// the nonce is not signed
// eslint-disable-next-line max-len
data.relayerAddress, data.from, data.encodedFunctionCall, toBN(data.txFee), toBN(data.gasPrice), toBN(data.gas)
Initial GSN support (beta) (#1844) * Add base Context contract * Add GSNContext and tests * Add RelayHub deployment to tests * Add RelayProvider integration, complete GSNContext tests * Switch dependency to openzeppelin-gsn-provider * Add default txfee to provider * Add basic signing recipient * Sign more values * Add comment clarifying RelayHub's msg.data * Make context constructors internal * Rename SigningRecipient to GSNRecipientSignedData * Add ERC20Charge recipients * Harcode RelayHub address into GSNContext * Fix Solidity linter errors * Run server from binary, use gsn-helpers to fund it * Migrate to published @openzeppelin/gsn-helpers * Silence false-positive compiler warning * Use GSN helper assertions * Rename meta-tx to gsn, take out of drafts * Merge ERC20 charge recipients into a single one * Rename GSNRecipients to Bouncers * Add GSNBouncerUtils to decouple the bouncers from GSNRecipient * Add _upgradeRelayHub * Store RelayHub address using unstructored storage * Add IRelayHub * Add _withdrawDeposits to GSNRecipient * Add relayHub version to recipient * Make _acceptRelayedCall and _declineRelayedCall easier to use * Rename GSNBouncerUtils to GSNBouncerBase, make it IRelayRecipient * Improve GSNBouncerBase, make pre and post sender-protected and optional * Fix GSNBouncerERC20Fee, add tests * Add missing GSNBouncerSignature test * Override transferFrom in __unstable__ERC20PrimaryAdmin * Fix gsn dependencies in package.json * Rhub address slot reduced by 1 * Rename relay hub changed event * Use released gsn-provider * Run relayer with short sleep of 1s instead of 100ms * update package-lock.json * clear circle cache * use optimized gsn-provider * update to latest @openzeppelin/gsn-provider * replace with gsn dev provider * remove relay server * rename arguments in approveFunction * fix GSNBouncerSignature test * change gsn txfee * initialize development provider only once * update RelayHub interface * adapt to new IRelayHub.withdraw * update @openzeppelin/gsn-helpers * update relayhub singleton address * fix helper name * set up gsn provider for coverage too * lint * Revert "set up gsn provider for coverage too" This reverts commit 8a7b5be5f942002710cba148f249cb888ee8e373. * remove unused code * add gsn provider to coverage * move truffle contract options back out * increase gas limit for coverage * remove unreachable code * add more gas for GSNContext test * fix test suite name * rename GSNBouncerBase internal API * remove onlyRelayHub modifier * add explicit inheritance * remove redundant event * update name of bouncers error codes enums * add basic docs page for gsn contracts * make gsn directory all caps * add changelog entry * lint * enable test run to fail in coverage
6 years ago
), signer
)
);
await gsn.expectError(this.recipient.mockFunction({ value: 0, useGSN: true, approveFunction }));
});
it('accepts relay requests where all parameters are signed', async function () {
const approveFunction = async (data) =>
fixSignature(
await web3.eth.sign(
web3.utils.soliditySha3(
// eslint-disable-next-line max-len
data.relayerAddress, data.from, data.encodedFunctionCall, toBN(data.txFee), toBN(data.gasPrice), toBN(data.gas), toBN(data.nonce), data.relayHubAddress, data.to
), signer
)
);
const { tx } = await this.recipient.mockFunction({ value: 0, useGSN: true, approveFunction });
await expectEvent.inTransaction(tx, GSNRecipientSignatureMock, 'MockFunctionCalled');
Initial GSN support (beta) (#1844) * Add base Context contract * Add GSNContext and tests * Add RelayHub deployment to tests * Add RelayProvider integration, complete GSNContext tests * Switch dependency to openzeppelin-gsn-provider * Add default txfee to provider * Add basic signing recipient * Sign more values * Add comment clarifying RelayHub's msg.data * Make context constructors internal * Rename SigningRecipient to GSNRecipientSignedData * Add ERC20Charge recipients * Harcode RelayHub address into GSNContext * Fix Solidity linter errors * Run server from binary, use gsn-helpers to fund it * Migrate to published @openzeppelin/gsn-helpers * Silence false-positive compiler warning * Use GSN helper assertions * Rename meta-tx to gsn, take out of drafts * Merge ERC20 charge recipients into a single one * Rename GSNRecipients to Bouncers * Add GSNBouncerUtils to decouple the bouncers from GSNRecipient * Add _upgradeRelayHub * Store RelayHub address using unstructored storage * Add IRelayHub * Add _withdrawDeposits to GSNRecipient * Add relayHub version to recipient * Make _acceptRelayedCall and _declineRelayedCall easier to use * Rename GSNBouncerUtils to GSNBouncerBase, make it IRelayRecipient * Improve GSNBouncerBase, make pre and post sender-protected and optional * Fix GSNBouncerERC20Fee, add tests * Add missing GSNBouncerSignature test * Override transferFrom in __unstable__ERC20PrimaryAdmin * Fix gsn dependencies in package.json * Rhub address slot reduced by 1 * Rename relay hub changed event * Use released gsn-provider * Run relayer with short sleep of 1s instead of 100ms * update package-lock.json * clear circle cache * use optimized gsn-provider * update to latest @openzeppelin/gsn-provider * replace with gsn dev provider * remove relay server * rename arguments in approveFunction * fix GSNBouncerSignature test * change gsn txfee * initialize development provider only once * update RelayHub interface * adapt to new IRelayHub.withdraw * update @openzeppelin/gsn-helpers * update relayhub singleton address * fix helper name * set up gsn provider for coverage too * lint * Revert "set up gsn provider for coverage too" This reverts commit 8a7b5be5f942002710cba148f249cb888ee8e373. * remove unused code * add gsn provider to coverage * move truffle contract options back out * increase gas limit for coverage * remove unreachable code * add more gas for GSNContext test * fix test suite name * rename GSNBouncerBase internal API * remove onlyRelayHub modifier * add explicit inheritance * remove redundant event * update name of bouncers error codes enums * add basic docs page for gsn contracts * make gsn directory all caps * add changelog entry * lint * enable test run to fail in coverage
6 years ago
});
it('rejects relay requests where all parameters are signed by an invalid signer', async function () {
const approveFunction = async (data) =>
fixSignature(
await web3.eth.sign(
web3.utils.soliditySha3(
// eslint-disable-next-line max-len
data.relayerAddress, data.from, data.encodedFunctionCall, toBN(data.txFee), toBN(data.gasPrice), toBN(data.gas), toBN(data.nonce), data.relayHubAddress, data.to
Initial GSN support (beta) (#1844) * Add base Context contract * Add GSNContext and tests * Add RelayHub deployment to tests * Add RelayProvider integration, complete GSNContext tests * Switch dependency to openzeppelin-gsn-provider * Add default txfee to provider * Add basic signing recipient * Sign more values * Add comment clarifying RelayHub's msg.data * Make context constructors internal * Rename SigningRecipient to GSNRecipientSignedData * Add ERC20Charge recipients * Harcode RelayHub address into GSNContext * Fix Solidity linter errors * Run server from binary, use gsn-helpers to fund it * Migrate to published @openzeppelin/gsn-helpers * Silence false-positive compiler warning * Use GSN helper assertions * Rename meta-tx to gsn, take out of drafts * Merge ERC20 charge recipients into a single one * Rename GSNRecipients to Bouncers * Add GSNBouncerUtils to decouple the bouncers from GSNRecipient * Add _upgradeRelayHub * Store RelayHub address using unstructored storage * Add IRelayHub * Add _withdrawDeposits to GSNRecipient * Add relayHub version to recipient * Make _acceptRelayedCall and _declineRelayedCall easier to use * Rename GSNBouncerUtils to GSNBouncerBase, make it IRelayRecipient * Improve GSNBouncerBase, make pre and post sender-protected and optional * Fix GSNBouncerERC20Fee, add tests * Add missing GSNBouncerSignature test * Override transferFrom in __unstable__ERC20PrimaryAdmin * Fix gsn dependencies in package.json * Rhub address slot reduced by 1 * Rename relay hub changed event * Use released gsn-provider * Run relayer with short sleep of 1s instead of 100ms * update package-lock.json * clear circle cache * use optimized gsn-provider * update to latest @openzeppelin/gsn-provider * replace with gsn dev provider * remove relay server * rename arguments in approveFunction * fix GSNBouncerSignature test * change gsn txfee * initialize development provider only once * update RelayHub interface * adapt to new IRelayHub.withdraw * update @openzeppelin/gsn-helpers * update relayhub singleton address * fix helper name * set up gsn provider for coverage too * lint * Revert "set up gsn provider for coverage too" This reverts commit 8a7b5be5f942002710cba148f249cb888ee8e373. * remove unused code * add gsn provider to coverage * move truffle contract options back out * increase gas limit for coverage * remove unreachable code * add more gas for GSNContext test * fix test suite name * rename GSNBouncerBase internal API * remove onlyRelayHub modifier * add explicit inheritance * remove redundant event * update name of bouncers error codes enums * add basic docs page for gsn contracts * make gsn directory all caps * add changelog entry * lint * enable test run to fail in coverage
6 years ago
), other
)
);
await gsn.expectError(this.recipient.mockFunction({ value: 0, useGSN: true, approveFunction }));
});
});
});