Skip to content

Commit 1cf4616

Browse files
committed
feat: update to alpha3
1 parent 643cd40 commit 1cf4616

File tree

11 files changed

+70579
-65154
lines changed

11 files changed

+70579
-65154
lines changed

__mocks__/ArgentAccount.json

Lines changed: 52141 additions & 50153 deletions
Large diffs are not rendered by default.

__mocks__/ERC20.json

Lines changed: 18275 additions & 14928 deletions
Large diffs are not rendered by default.

__tests__/__snapshots__/utils.browser.test.ts.snap

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

__tests__/__snapshots__/utils.test.ts.snap

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

__tests__/contracts.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@ const compiledERC20: CompiledContract = parse(
1313
);
1414

1515
describe('class Contract {}', () => {
16-
const address = randomAddress();
1716
const wallet = randomAddress();
18-
const contract = new Contract(compiledERC20.abi, address);
17+
let contract: Contract;
1918
beforeAll(async () => {
20-
const { code, tx_id } = await deployContract(compiledERC20, address);
19+
const {
20+
code,
21+
transaction_hash,
22+
address: erc20address,
23+
} = await deployContract(compiledERC20, []);
24+
console.log(erc20address);
25+
contract = new Contract(compiledERC20.abi, erc20address);
2126
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
2227
// eslint-disable-next-line no-console
23-
console.log('deployed erc20 contract', tx_id);
28+
console.log('deployed erc20 contract', transaction_hash);
2429
expect(code).toBe('TRANSACTION_RECEIVED');
25-
await waitForTx(tx_id);
30+
31+
await waitForTx(transaction_hash);
2632
});
2733
test('read initial balance of that account', async () => {
2834
const response = await contract.call('balance_of', {
@@ -39,8 +45,8 @@ describe('class Contract {}', () => {
3945

4046
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
4147
// eslint-disable-next-line no-console
42-
console.log('txId:', response.tx_id, ', funded wallet:', wallet);
43-
await waitForTx(response.tx_id);
48+
console.log('txId:', response.transaction_hash, ', funded wallet:', wallet);
49+
await waitForTx(response.transaction_hash);
4450
});
4551
test('read balance after mint of that account', async () => {
4652
const response = await contract.call('balance_of', {

__tests__/starknet.test.ts

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import fs from 'fs';
22

33
import {
44
CompiledContract,
5+
Contract,
56
addTransaction,
7+
callContract,
68
deployContract,
79
getBlock,
810
getCode,
@@ -12,6 +14,7 @@ import {
1214
getTransactionStatus,
1315
utils,
1416
} from '../src';
17+
import { getSelectorFromName } from '../src/utils/starknet';
1518

1619
const {
1720
json: { parse },
@@ -28,36 +31,51 @@ describe('starknet endpoints', () => {
2831
return expect(getContractAddresses()).resolves.not.toThrow();
2932
});
3033
test('getBlock()', () => {
31-
return expect(getBlock(46500)).resolves.not.toThrow();
34+
return expect(getBlock(870)).resolves.not.toThrow();
3235
});
3336
test('getBlock(blockId=null)', () => {
3437
return expect(getBlock()).resolves.not.toThrow();
3538
});
3639
test('getCode()', () => {
3740
return expect(
38-
getCode('0x5f778a983bf8760ad37868f4c869d70247c5546044a7f0386df96d8043d4e9d', 46500)
41+
getCode('0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61', 870)
3942
).resolves.not.toThrow();
4043
});
4144
test('getCode(blockId=null)', () => {
4245
return expect(
43-
getCode('0x5f778a983bf8760ad37868f4c869d70247c5546044a7f0386df96d8043d4e9d')
46+
getCode('0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61')
4447
).resolves.not.toThrow();
4548
});
4649
test('getStorageAt()', () => {
4750
return expect(
48-
getStorageAt('0x5f778a983bf8760ad37868f4c869d70247c5546044a7f0386df96d8043d4e9d', 0, 46500)
51+
getStorageAt('0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61', 0, 870)
4952
).resolves.not.toThrow();
5053
});
5154
test('getStorageAt(blockId=null)', () => {
5255
return expect(
53-
getStorageAt('0x5f778a983bf8760ad37868f4c869d70247c5546044a7f0386df96d8043d4e9d', 0)
56+
getStorageAt('0x163a1542a64402ffc93e39a4962eec51ce126f2e634631d3f1f6770a76e3a61', 0)
5457
).resolves.not.toThrow();
5558
});
5659
test('getTransactionStatus()', () => {
57-
return expect(getTransactionStatus(286136)).resolves.not.toThrow();
60+
return expect(
61+
getTransactionStatus('0x2086ff26645fb0e31a3e252302f3cb1e7612c60389102e5473dfc89758a3aa9')
62+
).resolves.not.toThrow();
5863
});
5964
test('getTransaction()', () => {
60-
return expect(getTransaction(286136)).resolves.not.toThrow();
65+
return expect(
66+
getTransaction('0x2086ff26645fb0e31a3e252302f3cb1e7612c60389102e5473dfc89758a3aa9')
67+
).resolves.not.toThrow();
68+
});
69+
test('callContract()', () => {
70+
return expect(
71+
callContract({
72+
contract_address: '0x58bceda58a83a5a100117ddc893234bad9c84a6833c2008f0f1ca90150149af',
73+
entry_point_selector: getSelectorFromName('balance_of'),
74+
calldata: Contract.compileCalldata({
75+
user: '0x58bceda58a83a5a100117ddc893234bad9c84a6833c2008f0f1ca90150149af',
76+
}),
77+
})
78+
).resolves.not.toThrow();
6179
});
6280
});
6381

@@ -72,27 +90,43 @@ describe('starknet endpoints', () => {
7290

7391
const response = await addTransaction({
7492
type: 'DEPLOY',
75-
contract_address: randomAddress(),
93+
contract_address_salt: randomAddress(),
94+
constructor_calldata: Contract.compileCalldata({
95+
signer: randomAddress(),
96+
guardian: '0',
97+
L1_address: '0',
98+
}),
7699
contract_definition: contractDefinition,
77100
});
101+
78102
expect(response.code).toBe('TRANSACTION_RECEIVED');
79-
expect(response.tx_id).toBeGreaterThan(0);
103+
expect(response.transaction_hash).toBeDefined();
104+
expect(response.address).toBeDefined();
80105

81106
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
82107
// eslint-disable-next-line no-console
83-
console.log('txId:', response.tx_id);
108+
console.log('txHash:', response.transaction_hash);
84109
});
85110

86111
test('deployContract()', async () => {
87112
const inputContract = compiledArgentAccount as unknown as CompiledContract;
88113

89-
const response = await deployContract(inputContract);
114+
const response = await deployContract(
115+
inputContract,
116+
Contract.compileCalldata({
117+
signer: randomAddress(),
118+
guardian: '0',
119+
L1_address: '0',
120+
})
121+
);
122+
90123
expect(response.code).toBe('TRANSACTION_RECEIVED');
91-
expect(response.tx_id).toBeGreaterThan(0);
124+
expect(response.transaction_hash).toBeDefined();
125+
expect(response.address).toBeDefined();
92126

93127
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
94128
// eslint-disable-next-line no-console
95-
console.log('txId:', response.tx_id);
129+
console.log('txHash:', response.transaction_hash);
96130
});
97131
});
98132
});

__tests__/wallet.test.ts

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,45 @@ describe('deploy and test Wallet', () => {
5353
console.log('PK:', pk);
5454

5555
const starkKeyPair = getKeyPair(pk);
56-
const walletAddress = getStarkKey(starkKeyPair);
57-
const wallet = new Contract(compiledArgentAccount.abi, walletAddress);
58-
const erc20Address = getStarkKey(getKeyPair(randomAddress()));
59-
const erc20 = new Contract(compiledErc20.abi, erc20Address);
56+
const starkKeyPub = getStarkKey(starkKeyPair);
57+
let wallet: Contract;
58+
let walletAddress: string;
59+
let erc20: Contract;
60+
let erc20Address: string;
6061
beforeAll(async () => {
61-
const { code: codeErc20, tx_id: txErc20 } = await deployContract(compiledErc20, erc20Address);
62+
const {
63+
code: codeErc20,
64+
transaction_hash: txErc20,
65+
address: erc20AddressLocal,
66+
} = await deployContract(compiledErc20, []);
67+
erc20Address = erc20AddressLocal;
68+
erc20 = new Contract(compiledErc20.abi, erc20Address);
6269
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
6370
// eslint-disable-next-line no-console
6471
console.log('deployed erc20', txErc20);
6572
expect(codeErc20).toBe('TRANSACTION_RECEIVED');
6673

67-
const { code, tx_id } = await deployContract(compiledArgentAccount, walletAddress);
74+
const {
75+
code,
76+
transaction_hash,
77+
address: walletAddressLocal,
78+
} = await deployContract(
79+
compiledArgentAccount,
80+
Contract.compileCalldata({
81+
signer: starkKeyPub,
82+
guardian: '0',
83+
L1_address: '0',
84+
}),
85+
starkKeyPub
86+
);
87+
walletAddress = walletAddressLocal;
88+
wallet = new Contract(compiledArgentAccount.abi, walletAddress);
6889
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
6990
// eslint-disable-next-line no-console
70-
console.log('deployed wallet', tx_id);
91+
console.log('deployed wallet', transaction_hash);
7192
expect(code).toBe('TRANSACTION_RECEIVED');
7293

73-
const { code: code2, tx_id: txId2 } = await wallet.invoke('initialize', {
74-
signer: walletAddress,
75-
guardian: '0',
76-
L1_address: '0',
77-
self_address: walletAddress,
78-
});
79-
80-
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
81-
// eslint-disable-next-line no-console
82-
console.log('initialized wallet', txId2);
83-
expect(code2).toBe('TRANSACTION_RECEIVED');
84-
85-
const { code: codeErc20Mint, tx_id: txErc20Mint } = await erc20.invoke('mint', {
94+
const { code: codeErc20Mint, transaction_hash: txErc20Mint } = await erc20.invoke('mint', {
8695
recipient: walletAddress,
8796
amount: '1000',
8897
});
@@ -119,20 +128,23 @@ describe('deploy and test Wallet', () => {
119128
);
120129

121130
const { r, s } = sign(starkKeyPair, msgHash);
122-
const { code, tx_id } = await wallet.invoke('execute', {
123-
to: erc20Address,
124-
selector: getSelectorFromName('transfer'),
125-
calldata: [erc20Address, '10'],
126-
nonce: nonce.toString(),
127-
sig: [toHex(r), toHex(s)],
128-
});
131+
const { code, transaction_hash } = await wallet.invoke(
132+
'execute',
133+
{
134+
to: erc20Address,
135+
selector: getSelectorFromName('transfer'),
136+
calldata: [erc20Address, '10'],
137+
nonce: nonce.toString(),
138+
},
139+
[toHex(r), toHex(s)]
140+
);
129141

130142
// I want to show the tx number to the tester, so he/she can trace the transaction in the explorer.
131143
// eslint-disable-next-line no-console
132-
console.log('transfer erc20 using wallet execute', tx_id);
144+
console.log('transfer erc20 using wallet execute', transaction_hash);
133145
expect(code).toBe('TRANSACTION_RECEIVED');
134146

135-
await waitForTx(tx_id);
147+
await waitForTx(transaction_hash);
136148
});
137149
test('read balance of wallet after transfer', async () => {
138150
const { res } = await erc20.call('balance_of', {

src/contract.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import assert from 'minimalistic-assert';
33

44
import { addTransaction, callContract } from './starknet';
55
import { Abi } from './types';
6-
import { toBN } from './utils/number';
6+
import { BigNumberish, toBN } from './utils/number';
77
import { getSelectorFromName } from './utils/starknet';
88

99
type Args = { [inputName: string]: string | string[] };
@@ -109,7 +109,7 @@ export class Contract {
109109
}, {} as Args);
110110
}
111111

112-
public invoke(method: string, args: Args = {}) {
112+
public invoke(method: string, args: Args = {}, signature?: [BigNumberish, BigNumberish]) {
113113
// ensure contract is connected
114114
assert(this.connectedTo !== null, 'contract isnt connected to an address');
115115

@@ -123,6 +123,7 @@ export class Contract {
123123
return addTransaction({
124124
type: 'INVOKE_FUNCTION',
125125
contract_address: this.connectedTo,
126+
signature,
126127
calldata,
127128
entry_point_selector: entrypointSelector,
128129
});

0 commit comments

Comments
 (0)