Browse Source

Test keccak256() on Solana

This requires Solana v1.6.9.

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 4 years ago
parent
commit
f88effa114

+ 1 - 1
.github/workflows/test.yml

@@ -118,7 +118,7 @@ jobs:
     needs: linux
     needs: linux
     services:
     services:
       solana:
       solana:
-        image: solanalabs/solana:v1.5.0
+        image: solanalabs/solana:v1.6.9
         ports:
         ports:
           - 8899
           - 8899
           - 8900
           - 8900

+ 1 - 1
docs/targets.rst

@@ -30,7 +30,7 @@ It can be used directly in the
 Solana
 Solana
 ______
 ______
 
 
-The Solana target requires `Solana <https://www.solana.com/>`_ 1.5.0 or later. This target is in the early stages right now,
+The Solana target requires `Solana <https://www.solana.com/>`_ 1.6.9 or later. This target is in the early stages right now,
 however it is under active development. All data types are supported, but the builtin functions, and constructor calls
 however it is under active development. All data types are supported, but the builtin functions, and constructor calls
 have not been implemented yet. This is how to build your Solidity for Solana:
 have not been implemented yet. This is how to build your Solidity for Solana:
 
 

+ 1 - 4
integration/solana/hash_functions.sol → integration/solana/builtins.sol

@@ -1,15 +1,12 @@
 
 
-contract hash_functions {
+contract builtins {
 	function hash_ripemd160(bytes bs) public returns (bytes20) {
 	function hash_ripemd160(bytes bs) public returns (bytes20) {
 		return ripemd160(bs);
 		return ripemd160(bs);
 	}
 	}
 
 
-/* this relies on Solana providing the sol_keccak256() syscall, which is
- * not available yet
 	function hash_kecccak256(bytes bs) public returns (bytes32) {
 	function hash_kecccak256(bytes bs) public returns (bytes32) {
 		return keccak256(bs);
 		return keccak256(bs);
 	}
 	}
-*/
 
 
 	function hash_sha256(bytes bs) public returns (bytes32) {
 	function hash_sha256(bytes bs) public returns (bytes32) {
 		return sha256(bs);
 		return sha256(bs);

+ 7 - 2
integration/solana/hash_functions.spec.ts → integration/solana/builtins.spec.ts

@@ -3,12 +3,12 @@ import { establishConnection } from './index';
 import crypto from 'crypto';
 import crypto from 'crypto';
 
 
 describe('Deploy solang contract and test', () => {
 describe('Deploy solang contract and test', () => {
-    it('hash function', async function () {
+    it('builtins', async function () {
         this.timeout(50000);
         this.timeout(50000);
 
 
         let conn = await establishConnection();
         let conn = await establishConnection();
 
 
-        let hash_functions = await conn.loadProgram("hash_functions.so", "hash_functions.abi");
+        let hash_functions = await conn.loadProgram("builtins.so", "builtins.abi");
 
 
         // call the constructor
         // call the constructor
         await hash_functions.call_constructor(conn, []);
         await hash_functions.call_constructor(conn, []);
@@ -23,6 +23,11 @@ describe('Deploy solang contract and test', () => {
 
 
         expect(res["0"]).toBe("0x458f3ceeeec730139693560ecf66c9c22d9c7bc7dcb0599e8e10b667dfeac043");
         expect(res["0"]).toBe("0x458f3ceeeec730139693560ecf66c9c22d9c7bc7dcb0599e8e10b667dfeac043");
 
 
+        console.log("calling keccak256");
+        res = await hash_functions.call_function(conn, "hash_kecccak256", ['0x' + Buffer.from('Call me Ishmael.', 'utf8').toString('hex')]);
+
+        expect(res["0"]).toBe("0x823ad8e1757b879aac338f9a18542928c668e479b37e4a56f024016215c5928c");
+
         console.log("calling timestamp");
         console.log("calling timestamp");
         res = await hash_functions.call_function(conn, "mr_now", []);
         res = await hash_functions.call_function(conn, "mr_now", []);
 
 

+ 1 - 1
integration/solana/package.json

@@ -18,7 +18,7 @@
     "typescript": "^4.1.2"
     "typescript": "^4.1.2"
   },
   },
   "dependencies": {
   "dependencies": {
-    "@solana/web3.js": "^0.87.1",
+    "@solana/web3.js": "^1.11.0",
     "web3-eth-abi": "^1.3.0",
     "web3-eth-abi": "^1.3.0",
     "web3-utils": "^1.3.0"
     "web3-utils": "^1.3.0"
   }
   }