How to use the sinon.replace function in sinon

To help you get started, we’ve selected a few sinon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mosaicdao / mosaic.js / test / stake_helper / isStakeAmountApproved.js View on Github external
);

    // Mock an instance of Value token contract.
    mockValueTokenContract = sinon.mock(
      Contracts.getEIP20Token(web3, valueTokenAddress),
    );
    const valueTokenContract = mockValueTokenContract.object;

    spyContract = sinon.replace(
      Contracts,
      'getEIP20Token',
      sinon.fake.returns(valueTokenContract),
    );

    // Fake the allowance call.
    spyGetAllowance = sinon.replace(
      valueTokenContract.methods,
      'allowance',
      sinon.fake.returns(() => {
        return Promise.resolve(approvedAmount);
      }),
    );

    // Add spy on stakeHelper.isBountyAmountApproved.
    spyIsStakeAmountApproved = sinon.spy(stakeHelper, 'isStakeAmountApproved');
  };
github OpenST / openst.js / test / unit / TokenHolder / getSessionKeyData.js View on Github external
it('should create the correct abi encoded data', async () => {
    const sessionKey = '0x0000000000000000000000000000000000000003';

    const mockSessionKeyData = 'mockSessionKeyData';
    const sessionKeyDataSpy = sinon.replace(
      tokenHolder.contract.methods,
      'sessionKeys',
      sinon.fake.returns({
        call: () => Promise.resolve(mockSessionKeyData)
      })
    );
    const response = await tokenHolder.getSessionKeyData(sessionKey);

    assert.strictEqual(response, mockSessionKeyData);
    Spy.assert(sessionKeyDataSpy, 1, [[sessionKey]]);
  });
github mosaicdao / mosaic.js / test / Anchor / getLatestInfo.js View on Github external
const setup = () => {
    spyCall = sinon.spy(anchor, 'getLatestInfo');
    spyGetLatestStateRootBlockHeight = sinon.replace(
      anchor,
      'getLatestStateRootBlockHeight',
      sinon.fake.resolves(getLatestStateRootBlockHeightResult),
    );
    spyGetStateRootResult = sinon.replace(
      anchor,
      'getStateRoot',
      sinon.fake.returns(getStateRootResult),
    );
  };
github mosaicdao / mosaic.js / test / EIP20Gateway / progressUnstake.js View on Github external
const setup = () => {
    spyRawTx = sinon.replace(
      gateway,
      'progressUnstakeRawTx',
      sinon.fake.resolves(mockedTx),
    );

    spyCall = sinon.spy(gateway, 'progressUnstake');

    spySendTransaction = sinon.replace(
      Utils,
      'sendTransaction',
      sinon.fake.resolves(true),
    );
  };
github mosaicdao / mosaic.js / test / Facilitator / performProgressStake.js View on Github external
const setup = () => {
    spyCall = sinon.spy(facilitator, 'performProgressStake');
    spyGetOutboxMessageStatus = sinon.replace(
      facilitator.gateway,
      'getOutboxMessageStatus',
      sinon.fake.resolves(getOutboxMessageStatusResult),
    );
    spyProgressStake = sinon.replace(
      facilitator.gateway,
      'progressStake',
      sinon.fake.resolves(progressStakeResult),
    );
  };
github mosaicdao / mosaic.js / test / EIP20CoGateway / getOutboxMessageStatus.js View on Github external
const setup = () => {
    spyMethod = sinon.replace(
      coGateway.contract.methods,
      'getOutboxMessageStatus',
      sinon.fake.returns(() => {
        return Promise.resolve(mockedMessageStatus);
      }),
    );

    spyCall = sinon.spy(coGateway, 'getOutboxMessageStatus');
  };
github mosaicdao / mosaic.js / test / Facilitator / progressStake.js View on Github external
const setup = () => {
    spyConfirmStakeIntent = sinon.replace(
      facilitator,
      'confirmStakeIntent',
      sinon.fake.resolves(confirmStakeIntentResult),
    );
    spyProgressStakeMessage = sinon.replace(
      facilitator,
      'progressStakeMessage',
      sinon.fake.resolves(progressStakeMessageResult),
    );
    spyGetMesageHash = sinon.replace(
      Message,
      'getStakeMessageHash',
      sinon.fake.returns(getMessageHashResult),
    );
    spyCall = sinon.spy(facilitator, 'progressStake');
  };
github mosaicdao / mosaic.js / test / EIP20CoGateway / confirmStakeIntent.js View on Github external
const setup = () => {
    spyRawTx = sinon.replace(
      coGateway,
      '_confirmStakeIntentRawTx',
      sinon.fake.resolves(mockedTx),
    );

    spyCall = sinon.spy(coGateway, 'confirmStakeIntent');

    spySendTransaction = sinon.replace(
      Utils,
      'sendTransaction',
      sinon.fake.resolves(true),
    );
  };
github mosaicdao / mosaic.js / test / Facilitator / confirmRedeemIntent.js View on Github external
spyGetOutboxMessageStatus = sinon.replace(
      facilitator.coGateway,
      'getOutboxMessageStatus',
      sinon.fake.resolves(getOutboxMessageStatusResult),
    );
    spyGetInboxMessageStatus = sinon.replace(
      facilitator.gateway,
      'getInboxMessageStatus',
      sinon.fake.resolves(getInboxMessageStatusResult),
    );
    spyGetCoGatewayProof = sinon.replace(
      facilitator,
      'getCoGatewayProof',
      sinon.fake.resolves(getCoGatewayProofResult),
    );
    spyProveGateway = sinon.replace(
      facilitator.gateway,
      'proveGateway',
      sinon.fake.resolves(proveGatewayResult),
    );
    spyConfirmRedeemIntent = sinon.replace(
      facilitator.gateway,
      'confirmRedeemIntent',
      sinon.fake.resolves(confirmRedeemIntentResult),
    );
    spyCall = sinon.spy(facilitator, 'confirmRedeemIntent');
  };
github mosaicdao / mosaic.js / test / EIP20Gateway / _progressUnstakeRawTx.js View on Github external
const setup = () => {
    spyMethod = sinon.replace(
      gateway.contract.methods,
      'progressUnstake',
      sinon.fake.resolves(mockedTx),
    );

    spyCall = sinon.spy(gateway, 'progressUnstakeRawTx');
  };