github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/js/src/test/175.test.ts (about)

     1  import * as assert from 'assert';
     2  import { compile } from '../contracts/compile';
     3  import { ContractInstance, getMetadata } from '../contracts/contract';
     4  import { client } from './test';
     5  
     6  describe('#175', function () {
     7    it('#175', async () => {
     8      const source = `
     9      pragma solidity >=0.0.0;
    10        contract Contract {
    11          string thename;
    12          constructor(string memory newName) public {
    13            thename = newName;
    14          }
    15          function getName() public view returns (string memory name) {
    16            return thename;
    17          }
    18        }
    19      `;
    20  
    21      const contract = compile<ContractInstance>(source, 'Contract');
    22  
    23      const instance1 = (await contract.deploy(client, 'contract1')) as any;
    24      const instance2 = await contract.deploy(client, 'contract2');
    25  
    26      const address = getMetadata(instance2).address;
    27      const ps = await Promise.all([
    28        // Note using the default address from the deploy
    29        instance1.getName(),
    30        // Using the .at() to specify the second deployed contract
    31        instance1.getName.at(address)(),
    32      ]);
    33      const [[name1], [name2]] = ps;
    34      assert.strictEqual(name1, 'contract1');
    35      assert.strictEqual(name2, 'contract2');
    36    });
    37  });