Error in Truffle test

I am creating DEX I have been getting error while testing my smart contracts

My Smart contract


  pragma solidity 0.8.6;

import "./Saubaan_2.sol";

contract  MySwap {
    string public name = "MySwap Ultimate Exchange";
    Saubaan_2 public token;
    uint public rate = 100;

    event TokenPurchased(
        address  account,
        address token,
        uint amount,
        uint rate
         
    ); 
  
 function buyTokens(address) public  payable  {
     // Calculate the number of tokens to buy
     uint tokenAmount = msg.value*rate;

     // Require that myswap has enough tokens
    require(token.balanceOf(address(this)) >= tokenAmount);
    // Transfer tokens to the user
     token.transfer(msg.sender, tokenAmount );

    // Emit an event
     emit TokenPurchased(msg.sender, address(token), tokenAmount, rate);

 }

My Test.js file

    const { assert } = require('chai');
const Saubaan_2= artifacts.require("Saubaan_2");
const MySwap = artifacts.require("MySwap");
require('chai')
 .use(require('chai-as-promised'))
 .should()
function tokens(n){
    return web3.utils.toWei(n, 'ether');
}

   contract('MySwap', (accounts) => {
       let token, myswap
    before(async() =>{
        token = await Saubaan_2.new()
         myswap = await MySwap.new()
         await token.transfer(myswap.address, tokens('1000000') )  
     })
     describe('Saubaan_2 deployment', async() => {
        it('contract has a name', async() => { 
            const name = await token.name()
            assert.equal(name , 'Saubaan 2')        
        })
    })
    
    describe('MySwap deployment', async() => {
        it('contract has a name', async() => {       
            const name = await myswap.name()
            assert.equal(name , 'MySwap Ultimate Exchange')              
     })
     it('contract has tokens', async() => {
       
        let balance = await token.balanceOf(myswap.address)
        assert.equal(balance.toString(),  tokens('1000000'))
   
        
       })
   
    })
    describe ('buyTokens()', async() => {
        let result 
        before( async() => {
            // pUrchase tokens before each example
           result = await myswap.buyTokens({from: accounts[1], value: web3.utils.toWei('1', 'ether')  })
        })
        it('Allows user to instantly buy tokens from myswap for a fixed price ',async() => {
            let investorBalance = await token.balanceOf(investor)
            assert.equal(investorBalance.toString(), tokens('100'))
            // Check myswap balance after purchase
            let myswapBalance 
            myswapBalance = await token.balanceOf(myswap.address)
            assert.equal(myswapBalance.toString(), tokens('99900'))
            myswapbalance = await web3.eth.getBalance(myswap.address)
            assert.equal(myswapBalance.toString(), web3.utils.toWei('1', 'ether')) 
           
        })

    })


    })

Now the error is occuring after this line
result = await myswap.buyTokens({from: accounts[1], value: web3.utils.toWei(‘1’, ‘ether’) })
If I comment out the above line my test is running fine.

Error shown after truffle test

1) Contract: MySwap
     buyTokens()
       "before all" hook for "Allows user to instantly buy tokens from myswap for a fixed price ":
   Error: Returned error: VM Exception while processing transaction: revert
    at Context.<anonymous> (test\MySwap.test.js:44:34)
    at processImmediate (internal/timers.js:464:21)

please help me I Want to become a good blockchain developer
Thanks in advance

Hi, welcome! :wave:

It looks like ok, so could you please share the code of the Saubaan_2.sol?

ok This is the code for Saubaan_2.sol

pragma solidity 0.8.6;

contract Saubaan_2 {
    string  public name = "Saubaan 2";
    string  public symbol = "SBN";
    uint256 public decimals = 18 ;
    uint256 public totalSupply = 1000000000000000000000000;

    event Transfer(
        address indexed _from,
        address indexed _to,
        uint256 _value
    );

    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint256 _value
    );

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    constructor() {
        balanceOf[msg.sender] = totalSupply;
    }

    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value);

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;

       emit Transfer(msg.sender, _to, _value);

        return true;
    }

    function approve(address _spender, uint256 _value) public returns (bool success) {
        allowance[msg.sender][_spender] = _value;

       emit Approval(msg.sender, _spender, _value);

        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(_value <= balanceOf[_from]);
        require(_value <= allowance[_from][msg.sender]);

        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;

        allowance[_from][msg.sender] -= _value;

       emit Transfer(_from, _to, _value);

        return true;
    }
}

Thanks for replying sir pls help me I want to become a good dveloper

SIr you did not reply me

What do you mean by this sir??

Variable investor haven’t been declared anywhere above that why the line below failed

Thanks sir this helped

Thank sir for your help I solved the error

If you Don’t mind Can you please help me become a blockchain developer I am new to this stuff. I want to become a good developer.

I would like very much to be personally in contact with you.

Thank you very much sir.