Skip to content

Commit 3c05937

Browse files
authored
🐛 Fix silent failures in C# tests (#208)
1 parent 49271ca commit 3c05937

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

clients/csharp/Solana.Unity.Bolt.Test/Framework.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ await Profiler.Run("RequestAirdrop", async () => {
8181
});
8282
}
8383

84-
public async Task<string> SendAndConfirmInstruction(IRpcClient client, TransactionInstruction instruction, List<Account>? signers = null, PublicKey? payer = null)
84+
public async Task<string> SendAndConfirmInstruction(IRpcClient client, TransactionInstruction instruction, List<Account>? signers = null, PublicKey? payer = null, bool mayFail = false)
8585
{
8686
if (signers == null) {
8787
signers = new List<Account> { Wallet.Account };
@@ -96,23 +96,31 @@ public async Task<string> SendAndConfirmInstruction(IRpcClient client, Transacti
9696
.AddInstruction(instruction)
9797
.Build(signers);
9898

99-
var signature = await client.SendTransactionAsync(transaction, true, Commitment.Processed);
99+
var signature = await client.SendTransactionAsync(transaction, false, Commitment.Processed);
100100
var confirmed = await client.ConfirmTransaction(signature.Result, Commitment.Processed);
101101
if (signature.WasSuccessful && confirmed)
102102
{
103103
return signature.Result;
104104
}
105-
string errorMessage = signature.Reason.ToString();
106-
errorMessage += "\n" + signature.RawRpcResponse;
107-
if (signature.ErrorData != null) {
108-
errorMessage += "\n" + string.Join("\n", signature.ErrorData.Logs);
105+
106+
if (mayFail) {
107+
return null;
108+
} else {
109+
string errorMessage = signature.Reason.ToString();
110+
errorMessage += "\n" + signature.RawRpcResponse;
111+
if (signature.ErrorData != null) {
112+
errorMessage += "\n" + string.Join("\n", signature.ErrorData.Logs);
113+
}
114+
115+
Console.WriteLine(errorMessage);
116+
Environment.Exit(1);
117+
return null;
109118
}
110-
throw new Exception(errorMessage);
111119
}
112120

113-
public async Task<string> SendAndConfirmInstruction(TransactionInstruction instruction, List<Account>? signers = null, PublicKey? payer = null)
121+
public async Task<string> SendAndConfirmInstruction(TransactionInstruction instruction, List<Account>? signers = null, PublicKey? payer = null, bool mayFail = false)
114122
{
115-
return await SendAndConfirmInstruction(Client, instruction, signers, payer);
123+
return await SendAndConfirmInstruction(Client, instruction, signers, payer, mayFail);
116124
}
117125

118126
public async Task<AccountInfo> GetAccountInfo(IRpcClient client, PublicKey publicKey)

clients/csharp/Solana.Unity.Bolt.Test/WorldTest.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ public static async Task InitializeRegistry(Framework framework) {
3131
};
3232

3333
TransactionInstruction instruction = WorldProgram.InitializeRegistry(initializeRegistry);
34-
try {
35-
await framework.SendAndConfirmInstruction(instruction);
36-
} catch (Exception) {
37-
// We ignore this error because it happens when the registry already exists
38-
}
39-
34+
await framework.SendAndConfirmInstruction(instruction, mayFail: true);
4035
}
4136

4237
public static async Task InitializeWorld(Framework framework) {

clients/typescript/src/generated/idl/world.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"address": "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n",
33
"metadata": {
44
"name": "world",
5-
"version": "0.2.4",
5+
"version": "0.2.6",
66
"spec": "0.1.0",
77
"description": "Bolt World program",
88
"repository": "https://github.com/magicblock-labs/bolt"

clients/typescript/src/generated/types/world.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type World = {
88
address: "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n";
99
metadata: {
1010
name: "world";
11-
version: "0.2.4";
11+
version: "0.2.6";
1212
spec: "0.1.0";
1313
description: "Bolt World program";
1414
repository: "https://github.com/magicblock-labs/bolt";

examples/system-simple-movement/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ custom-panic = []
2626
[dependencies]
2727
serde.workspace = true
2828
bolt-lang.workspace = true
29-
bolt-types = { version = "0.2.5", path = "../../crates/types" }
29+
bolt-types = { version = "0.2.6", path = "../../crates/types" }

0 commit comments

Comments
 (0)