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

     1  import * as assert from 'assert';
     2  import { compile } from '../contracts/compile';
     3  import { client } from './test';
     4  
     5  describe('#45', function () {
     6    it('Set/get memory string', async () => {
     7      const source = `
     8        pragma solidity >=0.0.0;
     9        contract Test {
    10            string _name;
    11  
    12            function add(int a, int b) public pure returns (int sum) {
    13                sum = a + b;
    14            }
    15  
    16            function setName(string memory newname) public {
    17               _name = newname;
    18            }
    19  
    20            function getName() public view returns (string memory) {
    21                return _name;
    22            }
    23        }
    24      `;
    25      const contract = compile(source, 'Test');
    26      return contract
    27        .deploy(client)
    28        .then((instance: any) => instance.setName('Batman').then(() => instance.getName()))
    29        .then((value) => {
    30          assert.deepStrictEqual(value, ['Batman']);
    31        });
    32    });
    33  
    34    it('get number/address', async () => {
    35      const source = `
    36        pragma solidity >=0.0.0;
    37        contract Test {
    38  
    39            function getAddress() public view returns (address) {
    40              return address(this);
    41            }
    42  
    43            function getNumber() public pure returns (uint) {
    44              return 100;
    45            }
    46  
    47        }
    48      `;
    49  
    50      const contract = compile(source, 'Test');
    51      return contract.deploy(client).then((instance: any) =>
    52        Promise.all([instance.getAddress(), instance.getNumber()]).then(([address, number]) => {
    53          assert.strictEqual(address[0].length, 40);
    54          assert.strictEqual(number[0], 100);
    55        }),
    56      );
    57    });
    58  });