@alephium/web3 0.2.0-rc.0 → 0.2.0-rc.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/.eslintignore +2 -2
  2. package/README.md +2 -135
  3. package/contracts/greeter/greeter.ral +3 -3
  4. package/contracts/greeter/greeter_interface.ral +1 -0
  5. package/contracts/greeter_main.ral +3 -5
  6. package/dist/alephium-web3.min.js +1 -1
  7. package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
  8. package/dist/alephium-web3.min.js.map +1 -1
  9. package/dist/scripts/create-project.js +3 -2
  10. package/dist/src/api/api-alephium.d.ts +46 -13
  11. package/dist/src/api/api-alephium.js +19 -3
  12. package/dist/src/api/api-explorer.d.ts +32 -16
  13. package/dist/src/api/api-explorer.js +26 -0
  14. package/dist/src/api/index.d.ts +3 -2
  15. package/dist/src/api/index.js +22 -3
  16. package/dist/src/api/types.d.ts +23 -0
  17. package/dist/src/api/types.js +240 -0
  18. package/dist/src/contract/contract.d.ts +104 -64
  19. package/dist/src/contract/contract.js +370 -426
  20. package/dist/src/contract/events.d.ts +4 -4
  21. package/dist/src/contract/index.js +5 -1
  22. package/dist/src/contract/ralph.d.ts +4 -4
  23. package/dist/src/global.d.ts +4 -0
  24. package/dist/src/global.js +38 -0
  25. package/dist/src/index.d.ts +2 -0
  26. package/dist/src/index.js +20 -1
  27. package/dist/src/signer/index.d.ts +0 -1
  28. package/dist/src/signer/index.js +5 -2
  29. package/dist/src/signer/signer.d.ts +21 -11
  30. package/dist/src/signer/signer.js +46 -9
  31. package/dist/src/transaction/index.d.ts +0 -1
  32. package/dist/src/transaction/index.js +5 -2
  33. package/dist/src/transaction/status.d.ts +2 -1
  34. package/dist/src/utils/index.d.ts +0 -1
  35. package/dist/src/utils/index.js +5 -2
  36. package/dist/src/utils/subscription.d.ts +0 -1
  37. package/dist/src/utils/subscription.js +2 -1
  38. package/dist/src/utils/utils.d.ts +5 -4
  39. package/dist/src/utils/utils.js +18 -17
  40. package/jest-config.json +11 -0
  41. package/package.json +7 -35
  42. package/scripts/create-project.ts +3 -2
  43. package/src/api/api-alephium.ts +56 -8
  44. package/src/api/api-explorer.ts +30 -0
  45. package/src/api/index.ts +14 -3
  46. package/src/api/types.ts +233 -0
  47. package/src/contract/contract.ts +537 -526
  48. package/src/contract/events.ts +6 -6
  49. package/src/contract/ralph.ts +4 -4
  50. package/src/{transaction/sign-verify.ts → global.ts} +14 -15
  51. package/src/index.ts +3 -0
  52. package/src/signer/index.ts +0 -1
  53. package/src/signer/signer.ts +70 -19
  54. package/src/transaction/index.ts +0 -1
  55. package/src/transaction/status.ts +4 -2
  56. package/src/utils/index.ts +0 -1
  57. package/src/utils/subscription.ts +3 -3
  58. package/src/utils/utils.ts +11 -11
  59. package/templates/base/package.json +2 -2
  60. package/templates/base/src/greeter.ts +10 -9
  61. package/templates/react/package.json +2 -2
  62. package/templates/react/src/App.tsx +2 -2
  63. package/.eslintrc.json +0 -21
  64. package/LICENSE +0 -165
  65. package/contracts/add/add.ral +0 -16
  66. package/contracts/main.ral +0 -6
  67. package/contracts/sub/sub.ral +0 -9
  68. package/dist/src/signer/node-wallet.d.ts +0 -13
  69. package/dist/src/signer/node-wallet.js +0 -60
  70. package/dist/src/test/index.d.ts +0 -7
  71. package/dist/src/test/index.js +0 -41
  72. package/dist/src/test/privatekey-wallet.d.ts +0 -12
  73. package/dist/src/test/privatekey-wallet.js +0 -68
  74. package/dist/src/transaction/sign-verify.d.ts +0 -2
  75. package/dist/src/transaction/sign-verify.js +0 -58
  76. package/dist/src/utils/password-crypto.d.ts +0 -2
  77. package/dist/src/utils/password-crypto.js +0 -69
  78. package/gitignore +0 -10
  79. package/src/contract/ralph.test.ts +0 -178
  80. package/src/fixtures/address.json +0 -36
  81. package/src/fixtures/balance.json +0 -9
  82. package/src/fixtures/self-clique.json +0 -19
  83. package/src/fixtures/transaction.json +0 -13
  84. package/src/fixtures/transactions.json +0 -179
  85. package/src/signer/fixtures/genesis.json +0 -26
  86. package/src/signer/fixtures/wallets.json +0 -26
  87. package/src/signer/node-wallet.ts +0 -74
  88. package/src/test/index.ts +0 -32
  89. package/src/test/privatekey-wallet.ts +0 -58
  90. package/src/transaction/sign-verify.test.ts +0 -50
  91. package/src/utils/address.test.ts +0 -47
  92. package/src/utils/djb2.test.ts +0 -35
  93. package/src/utils/password-crypto.test.ts +0 -27
  94. package/src/utils/password-crypto.ts +0 -77
  95. package/src/utils/utils.test.ts +0 -161
  96. package/test/contract.test.ts +0 -178
  97. package/test/events.test.ts +0 -138
  98. package/test/transaction.test.ts +0 -72
@@ -1,138 +0,0 @@
1
- /*
2
- Copyright 2018 - 2022 The Alephium Authors
3
- This file is part of the alephium project.
4
-
5
- The library is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU Lesser General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- The library is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public License
16
- along with the library. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- import { NodeProvider } from '../src/api'
20
- import { subscribeToEvents } from '../src/contract/events'
21
- import { Contract, Script } from '../src/contract'
22
- import { NodeWallet, SignExecuteScriptTxParams } from '../src/signer'
23
- import { ContractEvent } from '../src/api/api-alephium'
24
- import { testWallet } from '../src/test'
25
- import { SubscribeOptions, timeout } from '../src/utils'
26
-
27
- describe('events', function () {
28
- async function deployContract(provider: NodeProvider, signer: NodeWallet): Promise<[string, string]> {
29
- const sub = await Contract.fromSource(provider, 'sub/sub.ral')
30
- const subDeployTx = await sub.transactionForDeployment(signer, {
31
- initialFields: { result: 0 },
32
- initialTokenAmounts: []
33
- })
34
- const subContractId = subDeployTx.contractId
35
- const subSubmitResult = await signer.submitTransaction(subDeployTx.unsignedTx, subDeployTx.txId)
36
- expect(subSubmitResult.txId).toEqual(subDeployTx.txId)
37
-
38
- const add = await Contract.fromSource(provider, 'add/add.ral')
39
- const addDeployTx = await add.transactionForDeployment(signer, {
40
- initialFields: { subContractId: subContractId, result: 0 },
41
- initialTokenAmounts: []
42
- })
43
- const addSubmitResult = await signer.submitTransaction(addDeployTx.unsignedTx, addDeployTx.txId)
44
- expect(addSubmitResult.txId).toEqual(addDeployTx.txId)
45
- return [addDeployTx.contractAddress, addDeployTx.contractId]
46
- }
47
-
48
- async function executeScript(params: SignExecuteScriptTxParams, signer: NodeWallet, times: number) {
49
- for (let i = 0; i < times; i++) {
50
- const scriptTx = await signer.buildScriptTx(params)
51
- await signer.submitTransaction(scriptTx.unsignedTx, scriptTx.txId)
52
- }
53
- }
54
-
55
- it('should subscribe contract events', async () => {
56
- const provider = new NodeProvider('http://127.0.0.1:22973')
57
- const signer = await testWallet(provider)
58
-
59
- const [contractAddress, contractId] = await deployContract(provider, signer)
60
- const events: Array<ContractEvent> = []
61
- const subscriptOptions: SubscribeOptions<ContractEvent> = {
62
- provider: provider,
63
- pollingInterval: 500,
64
- messageCallback: (event: ContractEvent): Promise<void> => {
65
- events.push(event)
66
- return Promise.resolve()
67
- },
68
- errorCallback: (error: any, subscription): Promise<void> => {
69
- console.log(error)
70
- subscription.unsubscribe()
71
- return Promise.resolve()
72
- }
73
- }
74
- const subscription = subscribeToEvents(subscriptOptions, contractAddress)
75
- const script = await Script.fromSource(provider, 'main.ral')
76
- const scriptTxParams = await script.paramsForDeployment({
77
- initialFields: { addContractId: contractId },
78
- signerAddress: (await signer.getAccounts())[0].address
79
- })
80
- await executeScript(scriptTxParams, signer, 3)
81
- await timeout(3000)
82
-
83
- expect(events.length).toEqual(3)
84
- events.forEach((event) => {
85
- expect(event.fields).toEqual([
86
- { type: 'U256', value: '2' },
87
- { type: 'U256', value: '1' }
88
- ])
89
- })
90
- expect(subscription.currentEventCount()).toEqual(events.length)
91
-
92
- subscription.unsubscribe()
93
- }, 15000)
94
-
95
- it('should cancel event subscription', async () => {
96
- const provider = new NodeProvider('http://127.0.0.1:22973')
97
- const signer = await testWallet(provider)
98
-
99
- const [contractAddress, contractId] = await deployContract(provider, signer)
100
- const events: Array<ContractEvent> = []
101
- const subscriptOptions = {
102
- provider: provider,
103
- pollingInterval: 500,
104
- messageCallback: (event: ContractEvent): Promise<void> => {
105
- events.push(event)
106
- return Promise.resolve()
107
- },
108
- errorCallback: (error: any, subscription): Promise<void> => {
109
- console.log(error)
110
- subscription.unsubscribe()
111
- return Promise.resolve()
112
- }
113
- }
114
- const subscription = subscribeToEvents(subscriptOptions, contractAddress)
115
- const script = await Script.fromSource(provider, 'main.ral')
116
- const scriptTx0 = await script.transactionForDeployment(signer, {
117
- initialFields: { addContractId: contractId }
118
- })
119
- await signer.submitTransaction(scriptTx0.unsignedTx, scriptTx0.txId)
120
- await timeout(1500)
121
- subscription.unsubscribe()
122
-
123
- expect(events.length).toEqual(1)
124
- expect(events[0].txId).toEqual(scriptTx0.txId)
125
- expect(events[0].fields).toEqual([
126
- { type: 'U256', value: '2' },
127
- { type: 'U256', value: '1' }
128
- ])
129
- expect(subscription.currentEventCount()).toEqual(events.length)
130
-
131
- const scriptTx1 = await script.transactionForDeployment(signer, {
132
- initialFields: { addContractId: contractId }
133
- })
134
- await signer.submitTransaction(scriptTx1.unsignedTx, scriptTx1.txId)
135
- await timeout(1500)
136
- expect(events.length).toEqual(1)
137
- })
138
- })
@@ -1,72 +0,0 @@
1
- /*
2
- Copyright 2018 - 2022 The Alephium Authors
3
- This file is part of the alephium project.
4
-
5
- The library is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU Lesser General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- The library is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public License
16
- along with the library. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
- import { NodeProvider } from '../src/api'
20
- import { subscribeToTxStatus } from '../src/transaction/status'
21
- import { Contract } from '../src/contract'
22
- import { TxStatus } from '../src/api/api-alephium'
23
- import { testWallet } from '../src/test'
24
- import { SubscribeOptions, timeout } from '../src/utils'
25
-
26
- describe('transactions', function () {
27
- it('should subscribe transaction status', async () => {
28
- const provider = new NodeProvider('http://127.0.0.1:22973')
29
- const sub = await Contract.fromSource(provider, 'sub/sub.ral')
30
- const signer = await testWallet(provider)
31
- const subDeployTx = await sub.transactionForDeployment(signer, {
32
- initialFields: { result: 0 },
33
- initialTokenAmounts: []
34
- })
35
-
36
- let txStatus: TxStatus | undefined = undefined
37
- let counter = 0
38
- const subscriptOptions: SubscribeOptions<TxStatus> = {
39
- provider: provider,
40
- pollingInterval: 500,
41
- messageCallback: (status: TxStatus): Promise<void> => {
42
- txStatus = status
43
- counter = counter + 1
44
- return Promise.resolve()
45
- },
46
- errorCallback: (error: any, subscription): Promise<void> => {
47
- console.log(error)
48
- subscription.unsubscribe()
49
- return Promise.resolve()
50
- }
51
- }
52
-
53
- const counterBeforeSubscribe = counter
54
-
55
- const subscription = subscribeToTxStatus(subscriptOptions, subDeployTx.txId)
56
- await timeout(1500)
57
- expect(txStatus).toMatchObject({ type: 'TxNotFound' })
58
-
59
- const subSubmitResult = await signer.submitTransaction(subDeployTx.unsignedTx, subDeployTx.txId)
60
- await timeout(1500)
61
- expect(txStatus).toMatchObject({ type: 'Confirmed' })
62
-
63
- expect(counterBeforeSubscribe).toBeLessThan(counter)
64
-
65
- subscription.unsubscribe()
66
-
67
- const counterAfterUnsubscribe = counter
68
- await timeout(1500)
69
- expect(txStatus).toMatchObject({ type: 'Confirmed' })
70
- expect(counterAfterUnsubscribe).toEqual(counter)
71
- }, 10000)
72
- })