Skip to content

Commit 84e1926

Browse files
authored
Fix formatting for error string (#18)
#### Problem On-chain programs using `createProgramAddress` don't work currently because the format string specifies `{f}` for the error code. #### Summary of changes Fix all error formatting with `{d}` where appropriate.
1 parent 83c6621 commit 84e1926

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/public_key.zig

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub const PublicKey = extern struct {
107107
&address,
108108
);
109109
if (result != 0) {
110-
log.print("failed to create program address with seeds {any} and program id {f}: error code {f}", .{
110+
log.print("failed to create program address with seeds {any} and program id {f}: error code {d}", .{
111111
seeds,
112112
program_id,
113113
result,
@@ -170,7 +170,7 @@ pub const PublicKey = extern struct {
170170
&pda.bump_seed[0],
171171
);
172172
if (result != 0) {
173-
log.print("failed to find program address given seeds {any} and program id {f}: error code {f}", .{
173+
log.print("failed to find program address given seeds {any} and program id {f}: error code {d}", .{
174174
seeds,
175175
program_id,
176176
result,
@@ -230,13 +230,26 @@ test "public_key: comptime create program address" {
230230
try testing.expectFmt("2PjSSVURwJV4o9wz1BDVwwddvcUCuF1NKFpcQBF9emYJ", "{f}", .{address});
231231
}
232232

233+
test "public_key: create program address" {
234+
const id = comptime PublicKey.comptimeFromBase58("11111111111111111111111111111111");
235+
const address = try PublicKey.createProgramAddress(.{ "hello", &.{255} }, id);
236+
try testing.expectFmt("2PjSSVURwJV4o9wz1BDVwwddvcUCuF1NKFpcQBF9emYJ", "{f}", .{address});
237+
}
238+
233239
test "public_key: comptime find program address" {
234240
const id = comptime PublicKey.comptimeFromBase58("11111111111111111111111111111111");
235241
const pda = comptime PublicKey.comptimeFindProgramAddress(.{"hello"}, id);
236242
try testing.expectFmt("2PjSSVURwJV4o9wz1BDVwwddvcUCuF1NKFpcQBF9emYJ", "{f}", .{pda.address});
237243
try comptime testing.expectEqual(@as(u8, 255), pda.bump_seed[0]);
238244
}
239245

246+
test "public_key: find program address" {
247+
const id = comptime PublicKey.comptimeFromBase58("11111111111111111111111111111111");
248+
const pda = try PublicKey.findProgramAddress(.{"hello"}, id);
249+
try testing.expectFmt("2PjSSVURwJV4o9wz1BDVwwddvcUCuF1NKFpcQBF9emYJ", "{f}", .{pda.address});
250+
try testing.expectEqual(@as(u8, 255), pda.bump_seed[0]);
251+
}
252+
240253
test "public_key: equality" {
241254
const id = comptime PublicKey.comptimeFromBase58("11111111111111111111111111111111");
242255
const id2 = comptime PublicKey.comptimeFromBase58("11111111111111111111111111111111");

src/rent.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub const Rent = struct {
5555
};
5656
const result = Syscall.sol_get_rent_sysvar(&rent);
5757
if (result != 0) {
58-
log.print("failed to get rent sysvar: error code {f}", .{result});
58+
log.print("failed to get rent sysvar: error code {d}", .{result});
5959
return error.Unexpected;
6060
}
6161
}

0 commit comments

Comments
 (0)