github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/js/src/test/get-set.test.ts (about) 1 import * as assert from 'assert'; 2 import { compile } from '../contracts/compile'; 3 import { client } from './test'; 4 5 describe('Setting and Getting Values:', function () { 6 const source = ` 7 pragma solidity >=0.0.0; 8 9 contract GetSet { 10 11 uint uintfield; 12 bytes32 bytesfield; 13 string stringfield; 14 bool boolfield; 15 16 function testExist() public pure returns (uint output){ 17 return 1; 18 } 19 20 function setUint(uint input) public { 21 uintfield = input; 22 return; 23 } 24 25 function getUint() public view returns (uint output){ 26 output = uintfield; 27 return output; 28 } 29 30 function setBytes(bytes32 input) public { 31 bytesfield = input; 32 return; 33 } 34 35 function getBytes() public view returns (bytes32 output){ 36 output = bytesfield; 37 return output; 38 } 39 40 function setString(string memory input) public { 41 stringfield = input; 42 return; 43 } 44 45 function getString() public view returns (string memory output){ 46 output = stringfield; 47 return output; 48 } 49 50 function setBool(bool input) public { 51 boolfield = input; 52 return; 53 } 54 55 function getBool() public view returns (bool output){ 56 output = boolfield; 57 return output; 58 } 59 } 60 `; 61 62 const testUint = 42; 63 const testBytes = Buffer.from('DEADBEEF00000000000000000000000000000000000000000000000000000000', 'hex'); 64 const testString = 'Hello World!'; 65 const testBool = true; 66 67 let TestContract: any; 68 69 before(async () => { 70 const contract = compile(source, 'GetSet'); 71 TestContract = await contract.deploy(client); 72 }); 73 74 it('Uint', async () => { 75 await TestContract.setUint(testUint); 76 const output = await TestContract.getUint(); 77 assert.strictEqual(output[0], testUint); 78 }); 79 80 it('Bool', async () => { 81 await TestContract.setBool(testBool); 82 const output = await TestContract.getBool(); 83 assert.strictEqual(output[0], testBool); 84 }); 85 86 it('Bytes', async () => { 87 await TestContract.setBytes(testBytes); 88 const output = await TestContract.getBytes(); 89 assert.deepStrictEqual(output[0], testBytes); 90 }); 91 92 it('String', async () => { 93 await TestContract.setString(testString); 94 const output = await TestContract.getString(); 95 assert.strictEqual(output[0], testString); 96 }); 97 });