Skip to content

Commit 627d7dd

Browse files
committed
Test that migrations work
1 parent a65057e commit 627d7dd

3 files changed

Lines changed: 97 additions & 60 deletions

File tree

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bankrun-vault:
2222
(find programs && find tests) | entr -csr 'anchor build -p conditional_vault && RUST_LOG= yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/conditionalVault.ts'
2323

2424
bankrun-migrator:
25-
(find programs && find tests) | entr -csr 'anchor build -p autocrat_migrator && yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/migrator.ts'
25+
(find programs && find tests) | entr -csr 'anchor build -p autocrat_migrator && RUST_LOG= yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/migrator.ts'
2626

2727
bankrun-vault-logs:
2828
(find programs && find tests) | entr -csr 'anchor build -p conditional_vault && yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/conditionalVault.ts'

tests/autocratV0.ts

Lines changed: 88 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ import { expectError } from "./utils/utils";
3030

3131
import { AutocratV0 } from "../target/types/autocrat_v0";
3232
import { ConditionalVault } from "../target/types/conditional_vault";
33+
import { AutocratMigrator } from "../target/types/autocrat_migrator";
3334
import { OpenbookTwap } from "./fixtures/openbook_twap";
3435

3536
const OpenbookTwapIDL: OpenbookTwap = require("./fixtures/openbook_twap.json");
3637

3738
const AutocratIDL: AutocratV0 = require("../target/idl/autocrat_v0.json");
3839
const ConditionalVaultIDL: ConditionalVault = require("../target/idl/conditional_vault.json");
40+
const AutocratMigratorIDL: AutocratMigrator = require("../target/idl/autocrat_migrator.json");
3941

4042
export type PublicKey = anchor.web3.PublicKey;
4143
export type Signer = anchor.web3.Signer;
@@ -81,6 +83,11 @@ const OPENBOOK_PROGRAM_ID = new PublicKey(
8183
"opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb"
8284
);
8385

86+
const AUTOCRAT_MIGRATOR_PROGRAM_ID = new PublicKey(
87+
"8C4WEdr54tBPdtmeTPUBuZX5bgUMZw4XdvpNoNaQ6NwR"
88+
);
89+
90+
8491
describe("autocrat_v0", async function () {
8592
let provider,
8693
connection,
@@ -94,7 +101,10 @@ describe("autocrat_v0", async function () {
94101
USDC,
95102
vaultProgram,
96103
openbook,
97-
openbookTwap;
104+
openbookTwap,
105+
migrator,
106+
treasuryMetaAccount,
107+
treasuryUsdcAccount;
98108

99109
before(async function () {
100110
context = await startAnchor(
@@ -133,6 +143,12 @@ describe("autocrat_v0", async function () {
133143
provider
134144
);
135145

146+
migrator = new anchor.Program<AutocratMigrator>(
147+
AutocratMigratorIDL,
148+
AUTOCRAT_MIGRATOR_PROGRAM_ID,
149+
provider
150+
);
151+
136152
payer = autocrat.provider.wallet.payer;
137153

138154
USDC = await createMint(
@@ -142,6 +158,8 @@ describe("autocrat_v0", async function () {
142158
payer.publicKey,
143159
6
144160
);
161+
162+
META = await createMint(banksClient, payer, dao, dao, 9);
145163
});
146164

147165
describe("#initialize_dao", async function () {
@@ -155,7 +173,6 @@ describe("autocrat_v0", async function () {
155173
autocrat.programId
156174
);
157175

158-
META = await createMint(banksClient, payer, dao, dao, 9);
159176

160177
await autocrat.methods
161178
.initializeDao()
@@ -179,6 +196,9 @@ describe("autocrat_v0", async function () {
179196
assert.equal(daoAcc.passThresholdBps, 500);
180197
assert.ok(daoAcc.baseBurnLamports.eq(new BN(1_000_000_000).muln(50)));
181198
assert.ok(daoAcc.burnDecayPerSlotLamports.eq(new BN(46_300)));
199+
200+
treasuryMetaAccount = await createAssociatedTokenAccount(banksClient, payer, META, daoTreasury);
201+
treasuryUsdcAccount = await createAssociatedTokenAccount(banksClient, payer, USDC, daoTreasury);
182202
});
183203
});
184204

@@ -256,30 +276,55 @@ describe("autocrat_v0", async function () {
256276
aliceBaseFailConditionalTokenAccount,
257277
aliceQuotePassConditionalTokenAccount,
258278
aliceQuoteFailConditionalTokenAccount,
259-
newPassThresholdBps;
279+
newPassThresholdBps,
280+
instruction;
281+
260282

261283
beforeEach(async function () {
262-
const accounts = [
263-
{
264-
pubkey: dao,
265-
isSigner: false,
266-
isWritable: true,
267-
},
268-
{
269-
pubkey: daoTreasury,
270-
isSigner: true,
271-
isWritable: false,
272-
},
273-
];
274-
newPassThresholdBps = Math.floor(Math.random() * 1000);
275-
const data = autocrat.coder.instruction.encode("set_pass_threshold_bps", {
276-
passThresholdBps: newPassThresholdBps,
277-
});
278-
const instruction = {
279-
programId: autocrat.programId,
280-
accounts,
281-
data,
282-
};
284+
// const accounts = [
285+
// {
286+
// pubkey: dao,
287+
// isSigner: false,
288+
// isWritable: true,
289+
// },
290+
// {
291+
// pubkey: daoTreasury,
292+
// isSigner: true,
293+
// isWritable: false,
294+
// },
295+
// ];
296+
// newPassThresholdBps = Math.floor(Math.random() * 1000);
297+
// const data = autocrat.coder.instruction.encode("set_pass_threshold_bps", {
298+
// passThresholdBps: newPassThresholdBps,
299+
// });
300+
// const instruction = {
301+
// programId: autocrat.programId,
302+
// accounts,
303+
// data,
304+
// };
305+
306+
await mintToOverride(context, treasuryMetaAccount, 1_000_000_000n);
307+
await mintToOverride(context, treasuryUsdcAccount, 1_000_000n);
308+
309+
let receiver = Keypair.generate();
310+
let to0 = await createAccount(banksClient, payer, META, receiver.publicKey);
311+
let to1 = await createAccount(banksClient, payer, USDC, receiver.publicKey);
312+
313+
const ix = await migrator.methods.multiTransfer2()
314+
.accounts({
315+
authority: daoTreasury,
316+
from0: treasuryMetaAccount,
317+
to0,
318+
from1: treasuryUsdcAccount,
319+
to1,
320+
})
321+
.instruction();
322+
323+
instruction = {
324+
programId: ix.programId,
325+
accounts: ix.keys,
326+
data: ix.data,
327+
}
283328

284329
proposal = await initializeProposal(
285330
autocrat,
@@ -700,7 +745,7 @@ describe("autocrat_v0", async function () {
700745
.signers([mm0.keypair])
701746
.rpc();
702747

703-
await autocrat.methods
748+
let tx = await autocrat.methods
704749
.finalizeProposal()
705750
.accounts({
706751
proposal,
@@ -713,13 +758,19 @@ describe("autocrat_v0", async function () {
713758
daoTreasury,
714759
})
715760
.remainingAccounts(
716-
autocrat.instruction.setPassThresholdBps
717-
.accounts({
718-
dao,
719-
daoTreasury,
720-
})
761+
// autocrat.instruction.setPassThresholdBps
762+
// .accounts({
763+
// dao,
764+
// daoTreasury,
765+
// })
766+
// .concat({
767+
// pubkey: autocrat.programId,
768+
// isWritable: false,
769+
// isSigner: false,
770+
// })
771+
instruction.accounts
721772
.concat({
722-
pubkey: autocrat.programId,
773+
pubkey: migrator.programId,
723774
isWritable: false,
724775
isSigner: false,
725776
})
@@ -729,6 +780,7 @@ describe("autocrat_v0", async function () {
729780
: meta
730781
)
731782
)
783+
// .transaction();
732784
.rpc();
733785

734786
let storedBaseVault = await vaultProgram.account.conditionalVault.fetch(
@@ -744,8 +796,11 @@ describe("autocrat_v0", async function () {
744796
storedProposal = await autocrat.account.proposal.fetch(proposal);
745797
assert.exists(storedProposal.state.passed);
746798

747-
const storedDao = await autocrat.account.dao.fetch(dao);
748-
assert.equal(storedDao.passThresholdBps, newPassThresholdBps);
799+
assert((await getAccount(banksClient, treasuryMetaAccount)).amount == 0n);
800+
assert((await getAccount(banksClient, treasuryUsdcAccount)).amount == 0n);
801+
802+
// const storedDao = await autocrat.account.dao.fetch(dao);
803+
// assert.equal(storedDao.passThresholdBps, newPassThresholdBps);
749804

750805
await redeemConditionalTokens(
751806
vaultProgram,

tests/migrator.ts

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,13 @@ import { assert } from "chai";
99

1010
import {
1111
startAnchor,
12-
Clock,
13-
BanksClient,
14-
ProgramTestContext,
1512
} from "solana-bankrun";
16-
const AUTOCRAT_PROGRAM_ID = new PublicKey(
17-
"meta3cxKzFBmWYgCVozmvCQAS3y9b3fGxrG9HkHL7Wi"
18-
);
13+
1914
const AUTOCRAT_MIGRATOR_PROGRAM_ID = new PublicKey(
2015
"8C4WEdr54tBPdtmeTPUBuZX5bgUMZw4XdvpNoNaQ6NwR"
2116
);
22-
import { AutocratV0 } from "../target/types/autocrat_v0";
23-
const AutocratIDL: AutocratV0 = require("../target/idl/autocrat_v0.json");
24-
25-
import { expectError } from "./utils/utils";
2617

2718
import { AutocratMigrator } from "../target/types/autocrat_migrator";
28-
2919
const AutocratMigratorIDL: AutocratMigrator = require("../target/idl/autocrat_migrator.json");
3020

3121
export type PublicKey = anchor.web3.PublicKey;
@@ -35,9 +25,6 @@ export type Keypair = anchor.web3.Keypair;
3525
import {
3626
createMint,
3727
createAccount,
38-
createAssociatedTokenAccount,
39-
mintToOverride,
40-
getMint,
4128
getAccount,
4229
mintTo,
4330
} from "spl-token-bankrun";
@@ -50,8 +37,7 @@ describe("autocrat_migrator", async function () {
5037
context,
5138
banksClient,
5239
META,
53-
USDC,
54-
autocrat;
40+
USDC;
5541

5642
before(async function () {
5743
context = await startAnchor("./", [], []);
@@ -65,12 +51,6 @@ describe("autocrat_migrator", async function () {
6551
provider
6652
);
6753

68-
autocrat = new anchor.Program<AutocratV0>(
69-
AutocratIDL,
70-
AUTOCRAT_PROGRAM_ID,
71-
provider
72-
);
73-
7454
payer = migrator.provider.wallet.payer;
7555

7656
META = await createMint(
@@ -122,21 +102,23 @@ describe("autocrat_migrator", async function () {
122102

123103
await mintTo(banksClient, payer, META, from0, payer, 1_000_000);
124104
await mintTo(banksClient, payer, USDC, from1, payer, 10_000);
125-
console.log(await getAccount(banksClient, from0));
126105

127-
let tx = await migrator.methods
106+
await migrator.methods
128107
.multiTransfer2()
129108
.accounts({
130109
authority: payer.publicKey,
131-
lamportReceiver: receiver.publicKey,
132110
from0,
133111
to0,
134112
from1,
135113
to1,
136114
})
137115
.rpc();
116+
117+
assert((await getAccount(banksClient, from0)).amount == 0n);
118+
assert((await getAccount(banksClient, from1)).amount == 0n);
138119

139-
console.log(await getAccount(banksClient, from0));
120+
assert((await getAccount(banksClient, to0)).amount == 1_000_000n);
121+
assert((await getAccount(banksClient, to1)).amount == 10_000n);
140122
});
141123
});
142124
});

0 commit comments

Comments
 (0)