github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata/sha3.sol (about) 1 pragma solidity 0.4.24; 2 contract Sha3 { 3 function hashArray() constant returns(bytes32) { 4 bytes8[] memory tickers = new bytes8[](4); 5 tickers[0] = bytes8('BTC'); 6 tickers[1] = bytes8('ETH'); 7 tickers[2] = bytes8('LTC'); 8 tickers[3] = bytes8('DOGE'); 9 return sha3(tickers); 10 // 0x374c0504f79c1d5e6e4ded17d488802b5656bd1d96b16a568d6c324e1c04c37b 11 } 12 13 function hashPackedArray() constant returns(bytes32) { 14 bytes8 btc = bytes8('BTC'); 15 bytes8 eth = bytes8('ETH'); 16 bytes8 ltc = bytes8('LTC'); 17 bytes8 doge = bytes8('DOGE'); 18 return sha3(btc, eth, ltc, doge); 19 // 0xe79a6745d2205095147fd735f329de58377b2f0b9f4b81ae23e010062127f2bc 20 } 21 22 function hashAddress() constant returns(bytes32) { 23 address account = 0x6779913e982688474f710b47e1c0506c5dca4634; 24 return sha3(bytes20(account)); 25 // 0x229327de236bd04ccac2efc445f1a2b63afddf438b35874b9f6fd1e6c38b0198 26 } 27 28 function testPackedArgs() constant returns (bool) { 29 return sha3('ab') == sha3('a', 'b'); 30 } 31 32 function hashHex() constant returns (bytes32) { 33 return sha3(0x0a); 34 // 0x0ef9d8f8804d174666011a394cab7901679a8944d24249fd148a6a36071151f8 35 } 36 37 function hashInt() constant returns (bytes32) { 38 return sha3(int(1)); 39 } 40 41 function hashNegative() constant returns (bytes32) { 42 return sha3(int(-1)); 43 } 44 45 function hash8() constant returns (bytes32) { 46 return sha3(1); 47 } 48 49 function hash32() constant returns (bytes32) { 50 return sha3(uint32(1)); 51 } 52 53 function hash256() constant returns (bytes32) { 54 return sha3(uint(1)); 55 } 56 57 function hashEth() constant returns (bytes32) { 58 return sha3(uint(100 ether)); 59 } 60 61 function hashWei() constant returns (bytes32) { 62 return sha3(uint(100)); 63 } 64 65 function hashMultipleArgs() constant returns (bytes32) { 66 return sha3('a', uint(1)); 67 } 68 69 function hashString() constant returns (bytes32) { 70 return sha3('a'); 71 } 72 }