0

When getting contract's balance on Remix, it returns the correct answer. But when the same function is called with JS Test, it returns a lot of junk.

I referred to How to get a contract's balance in Solidity? but it does not work anymore or something is missing in my JS code.

Solidity:

function contractBalance() public view returns(uint) {
    return address(this).balance;
}

Javascript:

it('should return contracts balance', async function() {
    let contractBalance = await this.auction.contractBalance()
    console.log(contractBalance)
})

Output:

TruffleConfig {                                                                                                                                                                                                    
  _deepCopy: [ 'compilers' ],                                                                                                                                                                                      
  _values: {                                                                                                                                                                                                       
    truffle_directory: '/home/satoshi/.nvm/versions/node/v12.13.1/lib/node_modules/truffle',                                                                                                                       
    working_directory: '/home/satoshi/auction',                                                                                                                                                    
    network: 'development',                                                                                                                                                                                        
    networks: { development: [Object] },                                                                                                                                                                           
    verboseRpc: false,                                                                                                                                                                                             
    gas: null,                                                                                                                                                                                                     
    gasPrice: null,                                                                                                                                                                                                
    from: null,                                                                                                                                                                                                    
    confirmations: 0,                                                                                                                                                                                              
    timeoutBlocks: 0,                                                                                                                                                                                              
    production: false,                                                                                                                                                                                             
    skipDryRun: false,                                                                                                                                                                                             
    build: null,                                                                                                                                                                                                   
    resolver: TestResolver {                                                                                                                                                                                       
      resolver: [TestResolver],                                                                                                                                                                                    
      source: [TestSource],                                                                                                                                                                                        
      search_path: '/tmp/test-202034-9962-wwsk5l.xcbo',                                                                                                                                                            
      seen: [],                                     
      require_cache: {},                            
      cache_on: true                                
    },  
    ...
Dziugas
  • 141
  • 1
  • 8

1 Answers1

1

Use await this.auction.contractBalance().call().

goodvibration
  • 26,003
  • 5
  • 46
  • 86