Ver código fonte

:bug: Fix silent failures in C# tests (#208)

Danilo Guanabara 2 semanas atrás
pai
commit
3c0593741f

+ 17 - 9
clients/csharp/Solana.Unity.Bolt.Test/Framework.cs

@@ -81,7 +81,7 @@ namespace Solana.Unity.Bolt.Test
             });
         }
 
-        public async Task<string> SendAndConfirmInstruction(IRpcClient client, TransactionInstruction instruction, List<Account>? signers = null, PublicKey? payer = null)
+        public async Task<string> SendAndConfirmInstruction(IRpcClient client, TransactionInstruction instruction, List<Account>? signers = null, PublicKey? payer = null, bool mayFail = false)
         {
             if (signers == null) {
                 signers = new List<Account> { Wallet.Account };
@@ -96,23 +96,31 @@ namespace Solana.Unity.Bolt.Test
                 .AddInstruction(instruction)
                 .Build(signers);
 
-            var signature = await client.SendTransactionAsync(transaction, true, Commitment.Processed);
+            var signature = await client.SendTransactionAsync(transaction, false, Commitment.Processed);
             var confirmed = await client.ConfirmTransaction(signature.Result, Commitment.Processed);
             if (signature.WasSuccessful && confirmed)
             {
                 return signature.Result;
             }
-            string errorMessage = signature.Reason.ToString();
-            errorMessage += "\n" + signature.RawRpcResponse;
-            if (signature.ErrorData != null) {
-                errorMessage += "\n" + string.Join("\n", signature.ErrorData.Logs);
+
+            if (mayFail) {
+                return null;
+            } else {
+                string errorMessage = signature.Reason.ToString();
+                errorMessage += "\n" + signature.RawRpcResponse;
+                if (signature.ErrorData != null) {
+                    errorMessage += "\n" + string.Join("\n", signature.ErrorData.Logs);
+                }
+
+                Console.WriteLine(errorMessage);
+                Environment.Exit(1);
+                return null;
             }
-            throw new Exception(errorMessage);
         }
 
-        public async Task<string> SendAndConfirmInstruction(TransactionInstruction instruction, List<Account>? signers = null, PublicKey? payer = null)
+        public async Task<string> SendAndConfirmInstruction(TransactionInstruction instruction, List<Account>? signers = null, PublicKey? payer = null, bool mayFail = false)
         {
-            return await SendAndConfirmInstruction(Client, instruction, signers, payer);
+            return await SendAndConfirmInstruction(Client, instruction, signers, payer, mayFail);
         }
 
         public async Task<AccountInfo> GetAccountInfo(IRpcClient client, PublicKey publicKey)

+ 1 - 6
clients/csharp/Solana.Unity.Bolt.Test/WorldTest.cs

@@ -31,12 +31,7 @@ namespace WorldTest {
             };
 
             TransactionInstruction instruction = WorldProgram.InitializeRegistry(initializeRegistry);
-            try {
-                await framework.SendAndConfirmInstruction(instruction);
-            } catch (Exception) {
-                // We ignore this error because it happens when the registry already exists
-            }
-
+            await framework.SendAndConfirmInstruction(instruction, mayFail: true);
         }
 
         public static async Task InitializeWorld(Framework framework) {

+ 1 - 1
clients/typescript/src/generated/idl/world.json

@@ -2,7 +2,7 @@
   "address": "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n",
   "metadata": {
     "name": "world",
-    "version": "0.2.4",
+    "version": "0.2.6",
     "spec": "0.1.0",
     "description": "Bolt World program",
     "repository": "https://github.com/magicblock-labs/bolt"

+ 1 - 1
clients/typescript/src/generated/types/world.ts

@@ -8,7 +8,7 @@ export type World = {
   address: "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n";
   metadata: {
     name: "world";
-    version: "0.2.4";
+    version: "0.2.6";
     spec: "0.1.0";
     description: "Bolt World program";
     repository: "https://github.com/magicblock-labs/bolt";

+ 1 - 1
examples/system-simple-movement/Cargo.toml

@@ -26,4 +26,4 @@ custom-panic = []
 [dependencies]
 serde.workspace = true
 bolt-lang.workspace = true
-bolt-types = { version = "0.2.5", path = "../../crates/types" }
+bolt-types = { version = "0.2.6", path = "../../crates/types" }