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

     1  import * as assert from 'assert';
     2  import { compile } from '../contracts/compile';
     3  import { client } from './test';
     4  
     5  describe('memory bytes', function () {
     6    let instance: any;
     7  
     8    before(async () => {
     9      const source = `
    10        pragma solidity >=0.0.0;
    11        contract c {
    12          function getBytes() public pure returns (bytes1[10] memory){
    13              bytes1[10] memory b;
    14              string memory s = "hello";
    15              bytes memory sb = bytes(s);
    16  
    17              uint k = 0;
    18              for (uint i = 0; i < sb.length; i++) b[k++] = sb[i];
    19              b[9] = 0xff;
    20              return b;
    21          }
    22  
    23          function deeper() public pure returns (bytes1[12][100] memory s, uint count) {
    24            count = 42;
    25            return (s, count);
    26          }
    27        }
    28      `;
    29  
    30      const contract = compile(source, 'c');
    31      instance = await contract.deploy(client);
    32    });
    33  
    34    it('gets the static byte array decoded properly', async () => {
    35      const [bytes] = await instance.getBytes();
    36      assert.deepStrictEqual(
    37        bytes.map((b: Buffer) => b.toString('hex').toUpperCase()),
    38        ['68', '65', '6C', '6C', '6F', '00', '00', '00', '00', 'FF'],
    39      );
    40    });
    41  
    42    it('returns multiple values correctly from a function', async () => {
    43      const values = await instance.deeper();
    44      assert.strictEqual(values[1], 42);
    45    });
    46  });