Explorar o código

Increase timeout on Solana integration tests (#1111)

These regularly fail with timeouts, maybe this will work.

Signed-off-by: Sean Young <sean@mess.org>
Sean Young %!s(int64=2) %!d(string=hai) anos
pai
achega
b64681daf8
Modificáronse 2 ficheiros con 20 adicións e 15 borrados
  1. 1 2
      integration/anchor/tests/call_anchor.spec.ts
  2. 19 13
      integration/solana/setup.ts

+ 1 - 2
integration/anchor/tests/call_anchor.spec.ts

@@ -19,13 +19,12 @@ async function newAccountWithLamports(connection: Connection): Promise<Keypair>
 }
 
 describe('Call Anchor program from Solidity via IDL', () => {
-
     it('call_anchor', async function () {
         // This program instantiates an anchor program, calls various functions on it and checks the return values
 
         const connection = new Connection("http://localhost:8899", {
             commitment: "confirmed",
-            confirmTransactionInitialTimeout: 100000,
+            confirmTransactionInitialTimeout: 1e6,
         });
 
         const payer = await newAccountWithLamports(connection);

+ 19 - 13
integration/solana/setup.ts

@@ -11,10 +11,10 @@ export async function loadContract(name: string, args: any[] = [], space: number
 
     const abi = JSON.parse(fs.readFileSync(`${name}.abi`, 'utf8'));
 
-    const connection = new Connection(endpoint, 'confirmed');
+    const connection = newConnection();
 
-    const payerAccount = load_key('payer.key');
-    const program = load_key(`${name}.key`);
+    const payerAccount = loadKey('payer.key');
+    const program = loadKey(`${name}.key`);
 
     const storage = Keypair.generate();
     const contract = new Contract(connection, program.publicKey, storage.publicKey, abi, payerAccount);
@@ -25,9 +25,9 @@ export async function loadContract(name: string, args: any[] = [], space: number
 }
 
 export function newConnectionAndAccounts(name: string): [Connection, Keypair, Keypair] {
-    const connection = new Connection(endpoint, 'confirmed');
-    const payerAccount = load_key('payer.key');
-    const program = load_key(`${name}.key`);
+    const connection = newConnection();
+    const payerAccount = loadKey('payer.key');
+    const program = loadKey(`${name}.key`);
     return [connection, payerAccount, program];
 }
 
@@ -35,7 +35,7 @@ export async function loadContractWithExistingConnectionAndPayer(connection: Con
     const abi = JSON.parse(fs.readFileSync(`${name}.abi`, 'utf8'));
 
     const storage = Keypair.generate();
-    const program = load_key(`${name}.key`);
+    const program = loadKey(`${name}.key`);
     const contract = new Contract(connection, program.publicKey, storage.publicKey, abi, payerAccount);
 
     await contract.deploy(name, args, storage, space);
@@ -43,7 +43,7 @@ export async function loadContractWithExistingConnectionAndPayer(connection: Con
     return contract;
 }
 
-function load_key(filename: string): Keypair {
+function loadKey(filename: string): Keypair {
     const contents = fs.readFileSync(filename).toString();
     const bs = Uint8Array.from(JSON.parse(contents));
 
@@ -65,10 +65,7 @@ async function setup() {
         fs.writeFileSync(file_name, JSON.stringify(Array.from(key.secretKey)));
     };
 
-    const connection = new Connection(endpoint, {
-        commitment: "confirmed",
-        confirmTransactionInitialTimeout: 100000,
-    });
+    const connection = newConnection();
     const payer = await newAccountWithLamports(connection);
 
     write_key('payer.key', payer);
@@ -82,7 +79,7 @@ async function setup() {
             let program;
 
             if (fs.existsSync(`${name}.key`)) {
-                program = load_key(`${name}.key`);
+                program = loadKey(`${name}.key`);
             } else {
                 program = Keypair.generate();
             }
@@ -97,6 +94,15 @@ async function setup() {
     }
 }
 
+function newConnection(): Connection {
+    const connection = new Connection(endpoint, {
+        commitment: "confirmed",
+        confirmTransactionInitialTimeout: 1e6,
+    });
+
+    return connection;
+}
+
 if (require.main === module) {
     (async () => {
         await setup();