I have a 2 contracts

  1. Token A - Basic ERC20 Token
  2. Token B - An ERC20 Token which takes Token A

My question is more on solidity UNIT_TESTS plugin. From my understanding, I can only manipulate msg.sender and msg.value if my test contract inherits the contract I want to test.

My problem is that I am unable to test buying Token A while at the same time test buying Token B. I always get a reverted transaction during either an APPROVE or a TRANSFERFROM call.

Is possible to manipulate msg.sender and msg.value even if I do not inherit the Token contracts?

Token A

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import "./5_IERC20.sol";

contract AToken is IERC20 { //here be dragons, change name

//variable declarations

constructor() { 
    owner = msg.sender;

function buyAToken() public payable{
    //simple buy logic



Token B
// SPDX-License-Identifier: MIT
// NEW CHIT Token takes USDC
pragma solidity ^0.8.13;

import "./5_IERC20.sol";

contract BToken is IERC20 {

// ERC20 contract address
IERC20 public erc20Contract; //AToken address

constructor(IERC20 _erc20_contract_address) { //AToken address
    erc20Contract = _erc20_contract_address;

function buyToken(IERC20 token, uint256 amount) public payable { //amount of AToken user wants to buy

    uint256 amountBN = amount * 10 ** decimals;    

    uint256 price = calculatePrice(amount);

    token.transferFrom(msg.sender, address(corpAddress), price);
    balances[msg.sender] += amountBN;
    balances[zero] -= amountBN;

    weiRaised += price;
    tokensSold += amountBN;

    emit Transfer(zero, msg.sender, amountBN);

    emit TokenPurchase(



// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.13;
import "remix_tests.sol"; // this import is automatically injected by Remix.
import "remix_accounts.sol";
import "../contracts/1_AToken.sol";
import "../contracts/2_BToken.sol";

contract ATokenTest is BToken(new AToken()) {

AToken atoken;

function beforeAll () public {
    atoken = new AToken();
    atoken.setBalanceOf(acc7, 10000000000);
    Assert.equal(atoken.balanceOf(TestsAccounts.getAccount(7)), 10000000000, "Balance should be zero");
    Assert.equal(atoken.allowance(acc7, address(this)), 0, "Allowance should be zero at this point");

function buyB() public {
    atoken.approve(address(this), 10000000000);
    Assert.equal(atoken.allowance(acc7, address(this)), 10000000000, "Allowance should not be zero at this point");
    buyToken(this, 250);



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.