@alephium/web3 0.2.0-rc.6 → 0.2.0-rc.9
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.
- package/.eslintignore +2 -2
- package/README.md +2 -135
- package/contracts/greeter/greeter.ral +1 -1
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/scripts/create-project.js +1 -1
- package/dist/src/api/api-alephium.d.ts +19 -6
- package/dist/src/api/api-explorer.d.ts +16 -16
- package/dist/src/api/index.js +5 -1
- package/dist/src/contract/contract.d.ts +27 -10
- package/dist/src/contract/contract.js +105 -64
- package/dist/src/contract/index.js +5 -1
- package/dist/src/global.d.ts +3 -0
- package/{src/utils/djb2.test.ts → dist/src/global.js} +20 -17
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +20 -1
- package/dist/src/signer/index.d.ts +0 -1
- package/dist/src/signer/index.js +5 -2
- package/dist/src/signer/signer.d.ts +1 -1
- package/dist/src/signer/signer.js +8 -3
- package/dist/src/transaction/index.d.ts +0 -1
- package/dist/src/transaction/index.js +5 -2
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/utils/index.js +5 -2
- package/dist/src/utils/subscription.d.ts +0 -1
- package/dist/src/utils/subscription.js +2 -1
- package/dist/src/utils/utils.d.ts +3 -2
- package/dist/src/utils/utils.js +16 -15
- package/jest-config.json +11 -0
- package/package.json +6 -32
- package/scripts/create-project.ts +1 -1
- package/src/api/api-alephium.ts +14 -0
- package/src/contract/contract.ts +157 -69
- package/src/{test/index.ts → global.ts} +14 -10
- package/src/index.ts +3 -0
- package/src/signer/index.ts +0 -1
- package/src/signer/signer.ts +3 -2
- package/src/transaction/index.ts +0 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/subscription.ts +2 -2
- package/src/utils/utils.ts +7 -7
- package/templates/base/package.json +2 -2
- package/templates/base/src/greeter.ts +8 -7
- package/templates/react/package.json +2 -2
- package/templates/react/src/App.tsx +2 -2
- package/.eslintrc.json +0 -21
- package/LICENSE +0 -165
- package/contracts/add/add.ral +0 -13
- package/contracts/main.ral +0 -4
- package/contracts/sub/sub.ral +0 -10
- package/contracts/test/metadata.ral +0 -18
- package/contracts/test/warnings.ral +0 -8
- package/dist/src/signer/node-wallet.d.ts +0 -13
- package/dist/src/signer/node-wallet.js +0 -60
- package/dist/src/test/index.d.ts +0 -7
- package/dist/src/test/index.js +0 -41
- package/dist/src/test/privatekey-wallet.d.ts +0 -12
- package/dist/src/test/privatekey-wallet.js +0 -68
- package/dist/src/transaction/sign-verify.d.ts +0 -2
- package/dist/src/transaction/sign-verify.js +0 -58
- package/dist/src/utils/password-crypto.d.ts +0 -2
- package/dist/src/utils/password-crypto.js +0 -69
- package/gitignore +0 -9
- package/src/contract/ralph.test.ts +0 -178
- package/src/fixtures/address.json +0 -36
- package/src/fixtures/balance.json +0 -9
- package/src/fixtures/self-clique.json +0 -19
- package/src/fixtures/transaction.json +0 -13
- package/src/fixtures/transactions.json +0 -179
- package/src/signer/fixtures/genesis.json +0 -26
- package/src/signer/fixtures/wallets.json +0 -26
- package/src/signer/node-wallet.ts +0 -74
- package/src/test/privatekey-wallet.ts +0 -58
- package/src/transaction/sign-verify.test.ts +0 -50
- package/src/transaction/sign-verify.ts +0 -39
- package/src/utils/address.test.ts +0 -47
- package/src/utils/password-crypto.test.ts +0 -27
- package/src/utils/password-crypto.ts +0 -77
- package/src/utils/utils.test.ts +0 -161
- package/test/contract.test.ts +0 -213
- package/test/events.test.ts +0 -143
- package/test/transaction.test.ts +0 -74
package/test/events.test.ts
DELETED
|
@@ -1,143 +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 { Project, 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(signer: NodeWallet): Promise<[string, string]> {
|
|
29
|
-
const provider = new NodeProvider('http://127.0.0.1:22973')
|
|
30
|
-
await Project.build(provider)
|
|
31
|
-
const sub = Project.contract('sub/sub.ral')
|
|
32
|
-
const subDeployTx = await sub.transactionForDeployment(signer, {
|
|
33
|
-
initialFields: { result: 0 },
|
|
34
|
-
initialTokenAmounts: []
|
|
35
|
-
})
|
|
36
|
-
const subContractId = subDeployTx.contractId
|
|
37
|
-
const subSubmitResult = await signer.submitTransaction(subDeployTx.unsignedTx, subDeployTx.txId)
|
|
38
|
-
expect(subSubmitResult.txId).toEqual(subDeployTx.txId)
|
|
39
|
-
|
|
40
|
-
// ignore unused private function warnings
|
|
41
|
-
const add = Project.contract('add/add.ral', { errorOnWarnings: false })
|
|
42
|
-
const addDeployTx = await add.transactionForDeployment(signer, {
|
|
43
|
-
initialFields: { sub: subContractId, result: 0 },
|
|
44
|
-
initialTokenAmounts: []
|
|
45
|
-
})
|
|
46
|
-
const addSubmitResult = await signer.submitTransaction(addDeployTx.unsignedTx, addDeployTx.txId)
|
|
47
|
-
expect(addSubmitResult.txId).toEqual(addDeployTx.txId)
|
|
48
|
-
return [addDeployTx.contractAddress, addDeployTx.contractId]
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function executeScript(params: SignExecuteScriptTxParams, signer: NodeWallet, times: number) {
|
|
52
|
-
for (let i = 0; i < times; i++) {
|
|
53
|
-
const scriptTx = await signer.buildScriptTx(params)
|
|
54
|
-
await signer.submitTransaction(scriptTx.unsignedTx, scriptTx.txId)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
it('should subscribe contract events', async () => {
|
|
59
|
-
const provider = new NodeProvider('http://127.0.0.1:22973')
|
|
60
|
-
await Project.build(provider)
|
|
61
|
-
const signer = await testWallet(provider)
|
|
62
|
-
|
|
63
|
-
const [contractAddress, contractId] = await deployContract(signer)
|
|
64
|
-
const events: Array<ContractEvent> = []
|
|
65
|
-
const subscriptOptions: SubscribeOptions<ContractEvent> = {
|
|
66
|
-
provider: provider,
|
|
67
|
-
pollingInterval: 500,
|
|
68
|
-
messageCallback: (event: ContractEvent): Promise<void> => {
|
|
69
|
-
events.push(event)
|
|
70
|
-
return Promise.resolve()
|
|
71
|
-
},
|
|
72
|
-
errorCallback: (error: any, subscription): Promise<void> => {
|
|
73
|
-
console.log(error)
|
|
74
|
-
subscription.unsubscribe()
|
|
75
|
-
return Promise.resolve()
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const subscription = subscribeToEvents(subscriptOptions, contractAddress)
|
|
79
|
-
const script = Project.script('main.ral')
|
|
80
|
-
const scriptTxParams = await script.paramsForDeployment({
|
|
81
|
-
initialFields: { addContractId: contractId },
|
|
82
|
-
signerAddress: (await signer.getAccounts())[0].address
|
|
83
|
-
})
|
|
84
|
-
await executeScript(scriptTxParams, signer, 3)
|
|
85
|
-
await timeout(3000)
|
|
86
|
-
|
|
87
|
-
expect(events.length).toEqual(3)
|
|
88
|
-
events.forEach((event) => {
|
|
89
|
-
expect(event.fields).toEqual([
|
|
90
|
-
{ type: 'U256', value: '2' },
|
|
91
|
-
{ type: 'U256', value: '1' }
|
|
92
|
-
])
|
|
93
|
-
})
|
|
94
|
-
expect(subscription.currentEventCount()).toEqual(events.length)
|
|
95
|
-
|
|
96
|
-
subscription.unsubscribe()
|
|
97
|
-
}, 15000)
|
|
98
|
-
|
|
99
|
-
it('should cancel event subscription', async () => {
|
|
100
|
-
const provider = new NodeProvider('http://127.0.0.1:22973')
|
|
101
|
-
await Project.build(provider)
|
|
102
|
-
const signer = await testWallet(provider)
|
|
103
|
-
|
|
104
|
-
const [contractAddress, contractId] = await deployContract(signer)
|
|
105
|
-
const events: Array<ContractEvent> = []
|
|
106
|
-
const subscriptOptions = {
|
|
107
|
-
provider: provider,
|
|
108
|
-
pollingInterval: 500,
|
|
109
|
-
messageCallback: (event: ContractEvent): Promise<void> => {
|
|
110
|
-
events.push(event)
|
|
111
|
-
return Promise.resolve()
|
|
112
|
-
},
|
|
113
|
-
errorCallback: (error: any, subscription): Promise<void> => {
|
|
114
|
-
console.log(error)
|
|
115
|
-
subscription.unsubscribe()
|
|
116
|
-
return Promise.resolve()
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const subscription = subscribeToEvents(subscriptOptions, contractAddress)
|
|
120
|
-
const script = Project.script('main.ral')
|
|
121
|
-
const scriptTx0 = await script.transactionForDeployment(signer, {
|
|
122
|
-
initialFields: { addContractId: contractId }
|
|
123
|
-
})
|
|
124
|
-
await signer.submitTransaction(scriptTx0.unsignedTx, scriptTx0.txId)
|
|
125
|
-
await timeout(1500)
|
|
126
|
-
subscription.unsubscribe()
|
|
127
|
-
|
|
128
|
-
expect(events.length).toEqual(1)
|
|
129
|
-
expect(events[0].txId).toEqual(scriptTx0.txId)
|
|
130
|
-
expect(events[0].fields).toEqual([
|
|
131
|
-
{ type: 'U256', value: '2' },
|
|
132
|
-
{ type: 'U256', value: '1' }
|
|
133
|
-
])
|
|
134
|
-
expect(subscription.currentEventCount()).toEqual(events.length)
|
|
135
|
-
|
|
136
|
-
const scriptTx1 = await script.transactionForDeployment(signer, {
|
|
137
|
-
initialFields: { addContractId: contractId }
|
|
138
|
-
})
|
|
139
|
-
await signer.submitTransaction(scriptTx1.unsignedTx, scriptTx1.txId)
|
|
140
|
-
await timeout(1500)
|
|
141
|
-
expect(events.length).toEqual(1)
|
|
142
|
-
})
|
|
143
|
-
})
|
package/test/transaction.test.ts
DELETED
|
@@ -1,74 +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 { Project } 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
|
-
await Project.build(provider)
|
|
30
|
-
const sub = Project.contract('sub/sub.ral')
|
|
31
|
-
const signer = await testWallet(provider)
|
|
32
|
-
const subDeployTx = await sub.transactionForDeployment(signer, {
|
|
33
|
-
initialFields: { result: 0 },
|
|
34
|
-
initialTokenAmounts: []
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
let txStatus: TxStatus | undefined = undefined
|
|
38
|
-
let counter = 0
|
|
39
|
-
const subscriptOptions: SubscribeOptions<TxStatus> = {
|
|
40
|
-
provider: provider,
|
|
41
|
-
pollingInterval: 500,
|
|
42
|
-
messageCallback: (status: TxStatus): Promise<void> => {
|
|
43
|
-
txStatus = status
|
|
44
|
-
counter = counter + 1
|
|
45
|
-
return Promise.resolve()
|
|
46
|
-
},
|
|
47
|
-
errorCallback: (error: any, subscription): Promise<void> => {
|
|
48
|
-
console.log(error)
|
|
49
|
-
subscription.unsubscribe()
|
|
50
|
-
return Promise.resolve()
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const counterBeforeSubscribe = counter
|
|
55
|
-
|
|
56
|
-
const subscription = subscribeToTxStatus(subscriptOptions, subDeployTx.txId)
|
|
57
|
-
await timeout(1500)
|
|
58
|
-
expect(txStatus).toMatchObject({ type: 'TxNotFound' })
|
|
59
|
-
|
|
60
|
-
await signer.submitTransaction(subDeployTx.unsignedTx, subDeployTx.txId)
|
|
61
|
-
await timeout(1500)
|
|
62
|
-
expect(txStatus).toMatchObject({ type: 'Confirmed' })
|
|
63
|
-
|
|
64
|
-
expect(counterBeforeSubscribe).toBeLessThan(counter)
|
|
65
|
-
|
|
66
|
-
subscription.unsubscribe()
|
|
67
|
-
|
|
68
|
-
const counterAfterUnsubscribe = counter
|
|
69
|
-
await timeout(1500)
|
|
70
|
-
expect(txStatus).toMatchObject({ type: 'Confirmed' })
|
|
71
|
-
// There maybe a pending request when we unsubscribe
|
|
72
|
-
expect([counter, counter - 1]).toContain(counterAfterUnsubscribe)
|
|
73
|
-
}, 10000)
|
|
74
|
-
})
|