Skip to content

Commit 77dd3fb

Browse files
committed
Format
1 parent d499c9a commit 77dd3fb

File tree

4 files changed

+412
-389
lines changed

4 files changed

+412
-389
lines changed

src/__tests__/Anchor.test.ts

Lines changed: 106 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -26,120 +26,141 @@ test('Anchor', (done) => {
2626
.accounts({ fundingAccount: PublicKey.unique(), curMapping: PublicKey.unique(), nextMapping: PublicKey.unique() })
2727
.instruction()
2828
.then((instruction) => {
29-
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 1, 0, 0, 0]))
30-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
31-
expect(decoded?.name).toBe('addMapping')
32-
expect(decoded?.data).toStrictEqual({})
33-
})
34-
pythOracle.methods
35-
.updProduct()
36-
.accounts({ fundingAccount: PublicKey.unique(), productAccount: PublicKey.unique() })
37-
.instruction()
38-
.then((instruction) => {
39-
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 3, 0, 0, 0]))
40-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
41-
expect(decoded?.name).toBe('updProduct')
42-
expect(decoded?.data).toStrictEqual({})
43-
});
29+
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 1, 0, 0, 0]))
30+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
31+
expect(decoded?.name).toBe('addMapping')
32+
expect(decoded?.data).toStrictEqual({})
33+
})
34+
pythOracle.methods
35+
.updProduct()
36+
.accounts({ fundingAccount: PublicKey.unique(), productAccount: PublicKey.unique() })
37+
.instruction()
38+
.then((instruction) => {
39+
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 3, 0, 0, 0]))
40+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
41+
expect(decoded?.name).toBe('updProduct')
42+
expect(decoded?.data).toStrictEqual({})
43+
})
4444

45-
pythOracle.methods
46-
.addPrice(1,1)
45+
pythOracle.methods
46+
.addPrice(1, 1)
4747
.accounts({ fundingAccount: PublicKey.unique(), productAccount: PublicKey.unique() })
4848
.instruction()
4949
.then((instruction) => {
50-
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]))
51-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
52-
expect(decoded?.name).toBe('addPrice')
53-
expect(decoded?.data).toStrictEqual({expo: 1, pType: 1})
54-
});
50+
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]))
51+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
52+
expect(decoded?.name).toBe('addPrice')
53+
expect(decoded?.data).toStrictEqual({ expo: 1, pType: 1 })
54+
})
5555

56-
pythOracle.methods
56+
pythOracle.methods
5757
.addPublisher(new PublicKey(5))
5858
.accounts({ fundingAccount: PublicKey.unique(), priceAccount: PublicKey.unique() })
5959
.instruction()
6060
.then((instruction) => {
61-
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5]
62-
))
63-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
64-
expect(decoded?.name).toBe('addPublisher')
65-
expect(decoded?.data.pub.equals(new PublicKey(5))).toBeTruthy()
66-
});
61+
expect(instruction.data).toStrictEqual(
62+
Buffer.from([
63+
2, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64+
0, 0, 5,
65+
]),
66+
)
67+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
68+
expect(decoded?.name).toBe('addPublisher')
69+
expect(decoded?.data.pub.equals(new PublicKey(5))).toBeTruthy()
70+
})
6771

68-
pythOracle.methods
69-
.updPrice(1,0,new BN(42),new BN(9),new BN(1))
72+
pythOracle.methods
73+
.updPrice(1, 0, new BN(42), new BN(9), new BN(1))
7074
.accounts({ fundingAccount: PublicKey.unique(), priceAccount: PublicKey.unique() })
7175
.instruction()
7276
.then((instruction) => {
73-
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
74-
))
75-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
76-
expect(decoded?.name).toBe('updPrice')
77-
expect(decoded?.data.status ===1).toBeTruthy()
78-
expect(decoded?.data.price.eq(new BN(42))).toBeTruthy()
79-
expect(decoded?.data.conf.eq(new BN(9))).toBeTruthy()
80-
expect(decoded?.data.pubSlot.eq(new BN(1))).toBeTruthy()
81-
});
77+
expect(instruction.data).toStrictEqual(
78+
Buffer.from([
79+
2, 0, 0, 0, 7, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
80+
0, 0, 0, 0,
81+
]),
82+
)
83+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
84+
expect(decoded?.name).toBe('updPrice')
85+
expect(decoded?.data.status === 1).toBeTruthy()
86+
expect(decoded?.data.price.eq(new BN(42))).toBeTruthy()
87+
expect(decoded?.data.conf.eq(new BN(9))).toBeTruthy()
88+
expect(decoded?.data.pubSlot.eq(new BN(1))).toBeTruthy()
89+
})
8290

83-
pythOracle.methods
84-
.updPriceNoFailOnError(1,0,new BN(42),new BN(9),new BN(1))
91+
pythOracle.methods
92+
.updPriceNoFailOnError(1, 0, new BN(42), new BN(9), new BN(1))
8593
.accounts({ fundingAccount: PublicKey.unique(), priceAccount: PublicKey.unique() })
8694
.instruction()
8795
.then((instruction) => {
88-
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 13, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
89-
))
90-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
91-
expect(decoded?.name).toBe('updPriceNoFailOnError')
92-
expect(decoded?.data.status === 1).toBeTruthy()
93-
expect(decoded?.data.price.eq(new BN(42))).toBeTruthy()
94-
expect(decoded?.data.conf.eq(new BN(9))).toBeTruthy()
95-
expect(decoded?.data.pubSlot.eq(new BN(1))).toBeTruthy()
96-
});
96+
expect(instruction.data).toStrictEqual(
97+
Buffer.from([
98+
2, 0, 0, 0, 13, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
99+
0, 0, 0, 0,
100+
]),
101+
)
102+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
103+
expect(decoded?.name).toBe('updPriceNoFailOnError')
104+
expect(decoded?.data.status === 1).toBeTruthy()
105+
expect(decoded?.data.price.eq(new BN(42))).toBeTruthy()
106+
expect(decoded?.data.conf.eq(new BN(9))).toBeTruthy()
107+
expect(decoded?.data.pubSlot.eq(new BN(1))).toBeTruthy()
108+
})
97109

98-
pythOracle.methods
99-
.aggPrice(1,0,new BN(42),new BN(9),new BN(1))
110+
pythOracle.methods
111+
.aggPrice(1, 0, new BN(42), new BN(9), new BN(1))
100112
.accounts({ fundingAccount: PublicKey.unique(), priceAccount: PublicKey.unique() })
101113
.instruction()
102114
.then((instruction) => {
103-
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
104-
))
105-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
106-
expect(decoded?.name).toBe('aggPrice')
107-
expect(decoded?.data.status === 1).toBeTruthy()
108-
expect(decoded?.data.price.eq(new BN(42))).toBeTruthy()
109-
expect(decoded?.data.conf.eq(new BN(9))).toBeTruthy()
110-
expect(decoded?.data.pubSlot.eq(new BN(1))).toBeTruthy()
111-
});
115+
expect(instruction.data).toStrictEqual(
116+
Buffer.from([
117+
2, 0, 0, 0, 8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
118+
0, 0, 0, 0,
119+
]),
120+
)
121+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
122+
expect(decoded?.name).toBe('aggPrice')
123+
expect(decoded?.data.status === 1).toBeTruthy()
124+
expect(decoded?.data.price.eq(new BN(42))).toBeTruthy()
125+
expect(decoded?.data.conf.eq(new BN(9))).toBeTruthy()
126+
expect(decoded?.data.pubSlot.eq(new BN(1))).toBeTruthy()
127+
})
112128

113-
pythOracle.methods
114-
.setMinPub(5, [0,0,0])
129+
pythOracle.methods
130+
.setMinPub(5, [0, 0, 0])
115131
.accounts({ fundingAccount: PublicKey.unique(), priceAccount: PublicKey.unique() })
116132
.instruction()
117133
.then((instruction) => {
118-
expect(instruction.data).toStrictEqual(Buffer.from( [2, 0, 0, 0, 12, 0, 0, 0, 5, 0, 0, 0]
119-
))
120-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
121-
expect(decoded?.name).toBe('setMinPub')
122-
expect(decoded?.data.minPub ===5).toBeTruthy()
123-
});
134+
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 12, 0, 0, 0, 5, 0, 0, 0]))
135+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
136+
expect(decoded?.name).toBe('setMinPub')
137+
expect(decoded?.data.minPub === 5).toBeTruthy()
138+
})
124139

125-
pythOracle.methods
140+
pythOracle.methods
126141
.updPermissions(new PublicKey(6), new PublicKey(7), new PublicKey(8))
127-
.accounts({ upgradeAuthority: PublicKey.unique(), programAccount: PublicKey.unique(), programDataAccount: PublicKey.unique()})
142+
.accounts({
143+
upgradeAuthority: PublicKey.unique(),
144+
programAccount: PublicKey.unique(),
145+
programDataAccount: PublicKey.unique(),
146+
})
128147
.instruction()
129148
.then((instruction) => {
130-
const expectedPda = PublicKey.findProgramAddressSync([Buffer.from("permissions")], pythOracle.programId)[0];
131-
expect(expectedPda.equals(instruction.keys[3].pubkey));
132-
expect(instruction.data).toStrictEqual(Buffer.from( [2, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8]))
133-
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
134-
expect(decoded?.name).toBe('updPermissions')
135-
expect(decoded?.data.masterAuthority.equals(new PublicKey(6))).toBeTruthy()
136-
expect(decoded?.data.dataCurationAuthority.equals(new PublicKey(7))).toBeTruthy()
137-
expect(decoded?.data.securityAuthority.equals(new PublicKey(8))).toBeTruthy()
138-
});
139-
140-
141-
149+
const expectedPda = PublicKey.findProgramAddressSync([Buffer.from('permissions')], pythOracle.programId)[0]
150+
expect(expectedPda.equals(instruction.keys[3].pubkey))
151+
expect(instruction.data).toStrictEqual(
152+
Buffer.from([
153+
2, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
154+
0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0,
155+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
156+
]),
157+
)
158+
const decoded = (pythOracle.coder as PythOracleCoder).instruction.decode(instruction.data)
159+
expect(decoded?.name).toBe('updPermissions')
160+
expect(decoded?.data.masterAuthority.equals(new PublicKey(6))).toBeTruthy()
161+
expect(decoded?.data.dataCurationAuthority.equals(new PublicKey(7))).toBeTruthy()
162+
expect(decoded?.data.securityAuthority.equals(new PublicKey(8))).toBeTruthy()
163+
})
142164

143-
144165
done()
145166
})

src/anchor/coder/idl.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//
33
// https://github.com/coral-xyz/anchor/blob/master/ts/packages/anchor/src/coder/borsh/idl.ts
44

5-
65
import camelCase from 'camelcase'
76
import { Layout } from 'buffer-layout'
87
import * as borsh from '@coral-xyz/borsh'

src/anchor/coder/instructions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//
33
// https://github.com/coral-xyz/anchor/blob/master/ts/packages/anchor/src/coder/borsh/instruction.ts
44

5-
65
import bs58 from 'bs58'
76
import { Buffer } from 'buffer'
87
import { Layout } from 'buffer-layout'

0 commit comments

Comments
 (0)