difftreelog
Connection test now detects disconnection and added transfer test.
in: master
11 files changed
tests/.vscode/launch.jsondiffbeforeafterboth--- a/tests/.vscode/launch.json
+++ b/tests/.vscode/launch.json
@@ -1,23 +1,42 @@
{
- // Use IntelliSense to learn about possible attributes.
- // Hover to view descriptions of existing attributes.
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
- "version": "0.2.0",
- "configurations": [
- {
- "type": "node",
- "request": "launch",
- "name": "Mocha Current File",
- "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
- "args": [
- "--timeout", "999999",
- "--colors",
- "--recursive",
- "--require", "ts-node/register",
- "./**/*.test.ts"
- ],
- "console": "integratedTerminal",
- "internalConsoleOptions": "neverOpen"
- }
- ]
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "type": "node",
+ "request": "launch",
+ "name": "Mocha Current File",
+ "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
+ "args": [
+ "--timeout",
+ "9999999",
+ "--colors",
+ "--recursive",
+ "--require",
+ "ts-node/register",
+ "${file}"
+ ],
+ "console": "integratedTerminal",
+ "internalConsoleOptions": "neverOpen"
+ },
+ {
+ "type": "node",
+ "request": "launch",
+ "name": "Mocha All tests",
+ "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
+ "args": [
+ "--timeout",
+ "9999999",
+ "--colors",
+ "--recursive",
+ "--require",
+ "ts-node/register",
+ "./**/*.test.ts"
+ ],
+ "console": "integratedTerminal",
+ "internalConsoleOptions": "neverOpen"
+ }
+ ]
}
\ No newline at end of file
tests/package-lock.jsondiffbeforeafterboth3916 }3916 }3917 },3917 },3918 "@polkadot/api": {3918 "@polkadot/api": {3919 "version": "1.32.1",3919 "version": "1.31.2",3920 "resolved": "https://registry.npmjs.org/@polkadot/api/-/api-1.32.1.tgz",3920 "resolved": "https://registry.npmjs.org/@polkadot/api/-/api-1.31.2.tgz",3921 "integrity": "sha512-YwqvD7lmH18xPFggwqpXAQHH0DmwQcePVGLHb5c9JjX9QxYqPS5r+Ed6lFPqTBTTiYhb1ep8QZrY7TrgceP41g==",3921 "integrity": "sha512-5nMraRQYFt+xeInQi5i7c00fwOiSeZgU3Y1LJWz+z+Vnxep7xzjVBMLgBi4fe7g2eWKUYB79ApFNV8r2thsQZg==",3922 "requires": {3922 "requires": {3923 "@babel/runtime": "^7.11.2",3923 "@babel/runtime": "^7.11.2",3924 "@polkadot/api-derive": "1.32.1",3924 "@polkadot/api-derive": "1.31.2",3925 "@polkadot/keyring": "^3.4.1",3925 "@polkadot/keyring": "^3.4.1",3926 "@polkadot/metadata": "1.32.1",3926 "@polkadot/metadata": "1.31.2",3927 "@polkadot/rpc-core": "1.32.1",3927 "@polkadot/rpc-core": "1.31.2",3928 "@polkadot/rpc-provider": "1.32.1",3928 "@polkadot/rpc-provider": "1.31.2",3929 "@polkadot/types": "1.32.1",3929 "@polkadot/types": "1.31.2",3930 "@polkadot/types-known": "1.32.1",3930 "@polkadot/types-known": "1.31.2",3931 "@polkadot/util": "^3.4.1",3931 "@polkadot/util": "^3.4.1",3932 "@polkadot/util-crypto": "^3.4.1",3932 "@polkadot/util-crypto": "^3.4.1",3933 "bn.js": "^5.1.3",3933 "bn.js": "^5.1.3",3934 "eventemitter3": "^4.0.7",3934 "eventemitter3": "^4.0.6",3935 "rxjs": "^6.6.2"3935 "rxjs": "^6.6.2"3936 },3936 },3937 "dependencies": {3937 "dependencies": {3938 "@polkadot/metadata": {3939 "version": "1.31.2",3940 "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.31.2.tgz",3941 "integrity": "sha512-UAcZLxh6QFwhF2Ccmax6LUYa99NntBZrAe8oUN92UJlHbtAutd5sq322P+liG2EHfyhUZs5T5v8jLD79pMTjdA==",3942 "requires": {3943 "@babel/runtime": "^7.11.2",3944 "@polkadot/types": "1.31.2",3945 "@polkadot/types-known": "1.31.2",3946 "@polkadot/util": "^3.4.1",3947 "@polkadot/util-crypto": "^3.4.1",3948 "bn.js": "^5.1.3"3949 }3950 },3951 "@polkadot/types": {3952 "version": "1.31.2",3953 "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.31.2.tgz",3954 "integrity": "sha512-eJsWdMzBlkYYrowR7tl9LYvGW3Za05esDQPxPxc1z2kkwzU2IoX2qijhUb6J9ViESY/h0jWFyEbV/1mBn4uupg==",3955 "requires": {3956 "@babel/runtime": "^7.11.2",3957 "@polkadot/metadata": "1.31.2",3958 "@polkadot/util": "^3.4.1",3959 "@polkadot/util-crypto": "^3.4.1",3960 "@types/bn.js": "^4.11.6",3961 "bn.js": "^5.1.3",3962 "memoizee": "^0.4.14",3963 "rxjs": "^6.6.2"3964 }3965 },3966 "@polkadot/types-known": {3967 "version": "1.31.2",3968 "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.31.2.tgz",3969 "integrity": "sha512-sA9IEwYNCsN+Z4eZklxOluJA5OBN2eGNvLz0uUQ6TFvqbi9Z8Mba+h+RZU1iFO6+yq2U7ECvdWzET6RN7zv+oQ==",3970 "requires": {3971 "@babel/runtime": "^7.11.2",3972 "@polkadot/types": "1.31.2",3973 "@polkadot/util": "^3.4.1",3974 "bn.js": "^5.1.3"3975 }3976 },3938 "@polkadot/util": {3977 "@polkadot/util": {3939 "version": "3.4.1",3978 "version": "3.4.1",3940 "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-3.4.1.tgz",3979 "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-3.4.1.tgz",3951 }3990 }3952 },3991 },3953 "@polkadot/api-derive": {3992 "@polkadot/api-derive": {3954 "version": "1.32.1",3993 "version": "1.31.2",3955 "resolved": "https://registry.npmjs.org/@polkadot/api-derive/-/api-derive-1.32.1.tgz",3994 "resolved": "https://registry.npmjs.org/@polkadot/api-derive/-/api-derive-1.31.2.tgz",3956 "integrity": "sha512-i7kz2v8tHRl9RHKzvwc8OwjRyZVCwiP40CEpq0ZIgSl4wl2MpWcSMLrhbZdvRtBiVIfaogNb6esAZ1AFrtSDMQ==",3995 "integrity": "sha512-j33elEBZpY7/ucsBRYdUxeWHID8vlvPKm7k9dWgaH8txYuzms0SFfkMHyECgo15SL+RTNhu/VxzSRWryk6dvTA==",3957 "requires": {3996 "requires": {3958 "@babel/runtime": "^7.11.2",3997 "@babel/runtime": "^7.11.2",3959 "@polkadot/api": "1.32.1",3998 "@polkadot/api": "1.31.2",3960 "@polkadot/rpc-core": "1.32.1",3999 "@polkadot/rpc-core": "1.31.2",3961 "@polkadot/rpc-provider": "1.32.1",4000 "@polkadot/rpc-provider": "1.31.2",3962 "@polkadot/types": "1.32.1",4001 "@polkadot/types": "1.31.2",3963 "@polkadot/util": "^3.4.1",4002 "@polkadot/util": "^3.4.1",3964 "@polkadot/util-crypto": "^3.4.1",4003 "@polkadot/util-crypto": "^3.4.1",3965 "bn.js": "^5.1.3",4004 "bn.js": "^5.1.3",3966 "memoizee": "^0.4.14",4005 "memoizee": "^0.4.14",3967 "rxjs": "^6.6.2"4006 "rxjs": "^6.6.2"3968 },4007 },3969 "dependencies": {4008 "dependencies": {4009 "@polkadot/metadata": {4010 "version": "1.31.2",4011 "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.31.2.tgz",4012 "integrity": "sha512-UAcZLxh6QFwhF2Ccmax6LUYa99NntBZrAe8oUN92UJlHbtAutd5sq322P+liG2EHfyhUZs5T5v8jLD79pMTjdA==",4013 "requires": {4014 "@babel/runtime": "^7.11.2",4015 "@polkadot/types": "1.31.2",4016 "@polkadot/types-known": "1.31.2",4017 "@polkadot/util": "^3.4.1",4018 "@polkadot/util-crypto": "^3.4.1",4019 "bn.js": "^5.1.3"4020 }4021 },4022 "@polkadot/types": {4023 "version": "1.31.2",4024 "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.31.2.tgz",4025 "integrity": "sha512-eJsWdMzBlkYYrowR7tl9LYvGW3Za05esDQPxPxc1z2kkwzU2IoX2qijhUb6J9ViESY/h0jWFyEbV/1mBn4uupg==",4026 "requires": {4027 "@babel/runtime": "^7.11.2",4028 "@polkadot/metadata": "1.31.2",4029 "@polkadot/util": "^3.4.1",4030 "@polkadot/util-crypto": "^3.4.1",4031 "@types/bn.js": "^4.11.6",4032 "bn.js": "^5.1.3",4033 "memoizee": "^0.4.14",4034 "rxjs": "^6.6.2"4035 }4036 },4037 "@polkadot/types-known": {4038 "version": "1.31.2",4039 "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.31.2.tgz",4040 "integrity": "sha512-sA9IEwYNCsN+Z4eZklxOluJA5OBN2eGNvLz0uUQ6TFvqbi9Z8Mba+h+RZU1iFO6+yq2U7ECvdWzET6RN7zv+oQ==",4041 "requires": {4042 "@babel/runtime": "^7.11.2",4043 "@polkadot/types": "1.31.2",4044 "@polkadot/util": "^3.4.1",4045 "bn.js": "^5.1.3"4046 }4047 },3970 "@polkadot/util": {4048 "@polkadot/util": {3971 "version": "3.4.1",4049 "version": "3.4.1",3972 "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-3.4.1.tgz",4050 "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-3.4.1.tgz",4117 }4195 }4118 },4196 },4119 "@polkadot/rpc-core": {4197 "@polkadot/rpc-core": {4120 "version": "1.32.1",4198 "version": "1.31.2",4121 "resolved": "https://registry.npmjs.org/@polkadot/rpc-core/-/rpc-core-1.32.1.tgz",4199 "resolved": "https://registry.npmjs.org/@polkadot/rpc-core/-/rpc-core-1.31.2.tgz",4122 "integrity": "sha512-pre6aUVCQZqsoffGewyFzjM3MQ+kPn18n2L+B9EKqVBBd3+9v05X6aNmbm1aXb6laa0DzcuxO3EQmOT21CdbNQ==",4200 "integrity": "sha512-amFN0UtxB94TnXVuL9oBSQDFheCrxUN6C/lmVlOBqnWj6ZA1RDAuPPJBNIjhSxNlGmJxS2yIexaCVKgF8kS8Cg==",4123 "requires": {4201 "requires": {4124 "@babel/runtime": "^7.11.2",4202 "@babel/runtime": "^7.11.2",4125 "@polkadot/metadata": "1.32.1",4203 "@polkadot/metadata": "1.31.2",4126 "@polkadot/rpc-provider": "1.32.1",4204 "@polkadot/rpc-provider": "1.31.2",4127 "@polkadot/types": "1.32.1",4205 "@polkadot/types": "1.31.2",4128 "@polkadot/util": "^3.4.1",4206 "@polkadot/util": "^3.4.1",4129 "memoizee": "^0.4.14",4207 "memoizee": "^0.4.14",4130 "rxjs": "^6.6.2"4208 "rxjs": "^6.6.2"4131 },4209 },4132 "dependencies": {4210 "dependencies": {4211 "@polkadot/metadata": {4212 "version": "1.31.2",4213 "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.31.2.tgz",4214 "integrity": "sha512-UAcZLxh6QFwhF2Ccmax6LUYa99NntBZrAe8oUN92UJlHbtAutd5sq322P+liG2EHfyhUZs5T5v8jLD79pMTjdA==",4215 "requires": {4216 "@babel/runtime": "^7.11.2",4217 "@polkadot/types": "1.31.2",4218 "@polkadot/types-known": "1.31.2",4219 "@polkadot/util": "^3.4.1",4220 "@polkadot/util-crypto": "^3.4.1",4221 "bn.js": "^5.1.3"4222 }4223 },4224 "@polkadot/types": {4225 "version": "1.31.2",4226 "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.31.2.tgz",4227 "integrity": "sha512-eJsWdMzBlkYYrowR7tl9LYvGW3Za05esDQPxPxc1z2kkwzU2IoX2qijhUb6J9ViESY/h0jWFyEbV/1mBn4uupg==",4228 "requires": {4229 "@babel/runtime": "^7.11.2",4230 "@polkadot/metadata": "1.31.2",4231 "@polkadot/util": "^3.4.1",4232 "@polkadot/util-crypto": "^3.4.1",4233 "@types/bn.js": "^4.11.6",4234 "bn.js": "^5.1.3",4235 "memoizee": "^0.4.14",4236 "rxjs": "^6.6.2"4237 }4238 },4239 "@polkadot/types-known": {4240 "version": "1.31.2",4241 "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.31.2.tgz",4242 "integrity": "sha512-sA9IEwYNCsN+Z4eZklxOluJA5OBN2eGNvLz0uUQ6TFvqbi9Z8Mba+h+RZU1iFO6+yq2U7ECvdWzET6RN7zv+oQ==",4243 "requires": {4244 "@babel/runtime": "^7.11.2",4245 "@polkadot/types": "1.31.2",4246 "@polkadot/util": "^3.4.1",4247 "bn.js": "^5.1.3"4248 }4249 },4133 "@polkadot/util": {4250 "@polkadot/util": {4134 "version": "3.4.1",4251 "version": "3.4.1",4135 "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-3.4.1.tgz",4252 "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-3.4.1.tgz",4146 }4263 }4147 },4264 },4148 "@polkadot/rpc-provider": {4265 "@polkadot/rpc-provider": {4149 "version": "1.32.1",4266 "version": "1.31.2",4150 "resolved": "https://registry.npmjs.org/@polkadot/rpc-provider/-/rpc-provider-1.32.1.tgz",4267 "resolved": "https://registry.npmjs.org/@polkadot/rpc-provider/-/rpc-provider-1.31.2.tgz",4151 "integrity": "sha512-m3Vk7somPLrAfNM/z24XFQUD7lYrOZxa647uaCSGqGUNsszrcotBDBU3bE6WL5qOaR3EpLXs0Lhq6RpgowOqJg==",4268 "integrity": "sha512-vqS1lsk/BBGSuklGKJhJxduKXOyXjc/kZzPWmmH8B92Zh59LqlzoJ8a4gQIjDr0CFjeJZbaaL1yRhE6qwaEe2A==",4152 "requires": {4269 "requires": {4153 "@babel/runtime": "^7.11.2",4270 "@babel/runtime": "^7.11.2",4154 "@polkadot/metadata": "1.32.1",4271 "@polkadot/metadata": "1.31.2",4155 "@polkadot/types": "1.32.1",4272 "@polkadot/types": "1.31.2",4156 "@polkadot/util": "^3.4.1",4273 "@polkadot/util": "^3.4.1",4157 "@polkadot/util-crypto": "^3.4.1",4274 "@polkadot/util-crypto": "^3.4.1",4158 "bn.js": "^5.1.3",4275 "bn.js": "^5.1.3",4159 "eventemitter3": "^4.0.7",4276 "eventemitter3": "^4.0.6",4160 "isomorphic-fetch": "^2.2.1",4277 "isomorphic-fetch": "^2.2.1",4161 "websocket": "^1.0.32"4278 "websocket": "^1.0.31"4162 },4279 },4163 "dependencies": {4280 "dependencies": {4281 "@polkadot/metadata": {4282 "version": "1.31.2",4283 "resolved": "https://registry.npmjs.org/@polkadot/metadata/-/metadata-1.31.2.tgz",4284 "integrity": "sha512-UAcZLxh6QFwhF2Ccmax6LUYa99NntBZrAe8oUN92UJlHbtAutd5sq322P+liG2EHfyhUZs5T5v8jLD79pMTjdA==",4285 "requires": {4286 "@babel/runtime": "^7.11.2",4287 "@polkadot/types": "1.31.2",4288 "@polkadot/types-known": "1.31.2",4289 "@polkadot/util": "^3.4.1",4290 "@polkadot/util-crypto": "^3.4.1",4291 "bn.js": "^5.1.3"4292 }4293 },4294 "@polkadot/types": {4295 "version": "1.31.2",4296 "resolved": "https://registry.npmjs.org/@polkadot/types/-/types-1.31.2.tgz",4297 "integrity": "sha512-eJsWdMzBlkYYrowR7tl9LYvGW3Za05esDQPxPxc1z2kkwzU2IoX2qijhUb6J9ViESY/h0jWFyEbV/1mBn4uupg==",4298 "requires": {4299 "@babel/runtime": "^7.11.2",4300 "@polkadot/metadata": "1.31.2",4301 "@polkadot/util": "^3.4.1",4302 "@polkadot/util-crypto": "^3.4.1",4303 "@types/bn.js": "^4.11.6",4304 "bn.js": "^5.1.3",4305 "memoizee": "^0.4.14",4306 "rxjs": "^6.6.2"4307 }4308 },4309 "@polkadot/types-known": {4310 "version": "1.31.2",4311 "resolved": "https://registry.npmjs.org/@polkadot/types-known/-/types-known-1.31.2.tgz",4312 "integrity": "sha512-sA9IEwYNCsN+Z4eZklxOluJA5OBN2eGNvLz0uUQ6TFvqbi9Z8Mba+h+RZU1iFO6+yq2U7ECvdWzET6RN7zv+oQ==",4313 "requires": {4314 "@babel/runtime": "^7.11.2",4315 "@polkadot/types": "1.31.2",4316 "@polkadot/util": "^3.4.1",4317 "bn.js": "^5.1.3"4318 }4319 },4164 "@polkadot/util": {4320 "@polkadot/util": {4165 "version": "3.4.1",4321 "version": "3.4.1",4166 "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-3.4.1.tgz",4322 "resolved": "https://registry.npmjs.org/@polkadot/util/-/util-3.4.1.tgz",tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -16,7 +16,7 @@
"typescript": "^3.9.7"
},
"scripts": {
- "test": "mocha -r ts-node/register ./**/*.test.ts"
+ "test": "mocha --timeout 9999999 -r ts-node/register ./**/*.test.ts"
},
"author": "",
"license": "Apache 2.0",
tests/src/config.tsdiffbeforeafterboth--- a/tests/src/config.ts
+++ b/tests/src/config.ts
@@ -1,7 +1,71 @@
import process from 'process';
const config = {
- substrateUrl: process.env.substrateUrl || 'ws://127.0.0.1:9944'
+ substrateUrl: process.env.substrateUrl || 'ws://127.0.0.1:9944',
+ customTypes: process.env.customTypes || `{
+ "Schedule": {
+ "version": "u32",
+ "put_code_per_byte_cost": "Gas",
+ "grow_mem_cost": "Gas",
+ "regular_op_cost": "Gas",
+ "return_data_per_byte_cost": "Gas",
+ "event_data_per_byte_cost": "Gas",
+ "event_per_topic_cost": "Gas",
+ "event_base_cost": "Gas",
+ "call_base_cost": "Gas",
+ "instantiate_base_cost": "Gas",
+ "dispatch_base_cost": "Gas",
+ "sandbox_data_read_cost": "Gas",
+ "sandbox_data_write_cost": "Gas",
+ "transfer_cost": "Gas",
+ "instantiate_cost": "Gas",
+ "max_event_topics": "u32",
+ "max_stack_height": "u32",
+ "max_memory_pages": "u32",
+ "max_table_size": "u32",
+ "enable_println": "bool",
+ "max_subject_len": "u32"
+ },
+ "CollectionMode": {
+ "_enum": {
+ "Invalid": null,
+ "NFT": "u32",
+ "Fungible": "u32",
+ "ReFungible": "(u32, u32)"
+ }
+ },
+ "NftItemType": {
+ "Collection": "u64",
+ "Owner": "AccountId",
+ "Data": "Vec<u8>"
+ },
+ "Ownership": {
+ "owner": "AccountId",
+ "fraction": "u128"
+ },
+ "ReFungibleItemType": {
+ "Collection": "u64",
+ "Owner": "Vec<Ownership<AccountId>>",
+ "Data": "Vec<u8>"
+ },
+ "CollectionType": {
+ "Owner": "AccountId",
+ "Mode": "CollectionMode",
+ "Access": "u8",
+ "DecimalPoints": "u32",
+ "Name": "Vec<u16>",
+ "Description": "Vec<u16>",
+ "TokenPrefix": "Vec<u8>",
+ "CustomDataSize": "u32",
+ "OffchainSchema": "Vec<u8>",
+ "Sponsor": "AccountId",
+ "UnconfirmedSponsor": "AccountId"
+ },
+ "RawData": "Vec<u8>",
+ "Address": "AccountId",
+ "LookupSource": "AccountId",
+ "Weight": "u64"
+ }`
}
export default config;
\ No newline at end of file
tests/src/connection.test.tsdiffbeforeafterboth--- a/tests/src/connection.test.ts
+++ b/tests/src/connection.test.ts
@@ -1,10 +1,11 @@
-import createSubstrateApi from "./substrate-api";
import {expect} from 'chai';
+import usingApi from "./substrate/substrate-api";
describe('Connection', () => {
it('Connection can be established', async () => {
- const api = await createSubstrateApi();
- const health = await api.rpc.system.health();
- expect(health).to.be.not.empty;
+ await usingApi(async api => {
+ const health = await api.rpc.system.health();
+ expect(health).to.be.not.empty;
+ });
});
});
\ No newline at end of file
tests/src/substrate-api.tsdiffbeforeafterboth--- a/tests/src/substrate-api.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { WsProvider, ApiPromise } from "@polkadot/api";
-import config from "./config";
-
-const wsProvider = new WsProvider(config.substrateUrl);
-const settings = { provider: wsProvider };
-
-
-export default function createSubstrateApi(): Promise<ApiPromise> {
- return new ApiPromise(settings).isReady;
-}
\ No newline at end of file
tests/src/substrate/promisify-substrate.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/substrate/promisify-substrate.ts
@@ -0,0 +1,32 @@
+import ApiPromise from "@polkadot/api/promise/Api";
+
+type PromiseType<T> = T extends PromiseLike<infer TInner> ? TInner : T;
+
+export default function promisifySubstrate<T extends (...args: any[]) => any>(api: ApiPromise, action: T): (...args: Parameters<T>) => Promise<PromiseType<ReturnType<T>>> {
+ return (...args: Parameters<T>) => {
+ const promise = new Promise<PromiseType<ReturnType<T>>>((resolve, reject) => {
+ const cleanup = () => {
+ api.off('disconnected', fail);
+ api.off('error', fail);
+ };
+
+ const success = (r: any) => {
+ cleanup();
+ resolve(r);
+ };
+ const fail = (error: any) => {
+ cleanup();
+ reject(error);
+ };
+
+ api.on('disconnected', fail);
+ api.on('error', fail);
+
+ const result = action(...args);
+ Promise.resolve(result)
+ .then(success, fail);
+
+ });
+ return promise as any;
+ };
+}
tests/src/substrate/substrate-api.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/substrate/substrate-api.ts
@@ -0,0 +1,18 @@
+import { WsProvider, ApiPromise } from "@polkadot/api";
+import config from "../config";
+import promisifySubstrate from "./promisify-substrate";
+import { ApiOptions } from "@polkadot/api/types";
+
+export default async function usingApi(action: (api: ApiPromise) => Promise<void>): Promise<void> {
+ const wsProvider = new WsProvider(config.substrateUrl);
+ const settings: ApiOptions = { provider: wsProvider, types: JSON.parse(config.customTypes) };
+ let api: ApiPromise | undefined = undefined;
+
+ try {
+ api = await ApiPromise.create(settings);
+ await promisifySubstrate(api, () => api && api.isReady)();
+ await action(api);
+ } finally {
+ api && api.disconnect();
+ }
+}
\ No newline at end of file
tests/src/substrate/wait-new-blocks.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/substrate/wait-new-blocks.ts
@@ -0,0 +1,17 @@
+import { ApiPromise } from "@polkadot/api";
+
+export default function waitNewBlocks(api: ApiPromise, blocksCount: number = 1): Promise<void> {
+ const promise = new Promise<void>(async (resolve, reject) => {
+
+ const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
+ if(blocksCount > 0) {
+ blocksCount--;
+ }else {
+ unsubscribe();
+ resolve();
+ }
+ });
+ });
+
+ return promise;
+}
\ No newline at end of file
tests/src/transfer.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/transfer.test.ts
@@ -0,0 +1,38 @@
+import createSubstrateApi from "./substrate/substrate-api";
+import { Keyring, ApiPromise } from "@polkadot/api";
+import {AccountInfo} from "@polkadot/types/interfaces/system";
+import { expect } from "chai";
+import usingApi from "./substrate/substrate-api";
+import promisifySubstrate from "./substrate/promisify-substrate";
+import waitNewBlocks from "./substrate/wait-new-blocks";
+
+async function getBalance(api: ApiPromise, accounts: string[]): Promise<bigint[]> {
+ const balance = promisifySubstrate(api, (accounts: string[]) => api.query.system.account.multi(accounts));
+ const responce = await balance(accounts) as unknown as AccountInfo[];
+ return responce.map(r => r.data.free.toBigInt().valueOf());
+}
+
+describe('Transfer', () => {
+ it('Balance transfers', async () => {
+ const bobsPublicKey = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
+ const alicesPublicKey = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
+ await usingApi(async api => {
+ const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
+
+ const keyring = new Keyring({ type: 'sr25519' });
+
+ const alicePrivateKey = keyring.addFromUri('//Alice');
+
+ const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);
+
+ const hash = await transfer.signAndSend(alicePrivateKey);
+
+ await waitNewBlocks(api);
+
+ const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
+
+ expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;
+ expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;
+ });
+ });
+});
tests/tsconfig.jsondiffbeforeafterboth--- a/tests/tsconfig.json
+++ b/tests/tsconfig.json
@@ -5,7 +5,7 @@
"**/node_modules/**/*"
],
"compilerOptions": {
- "target": "es6",
+ "target": "ES2020",
"moduleResolution": "node",
"esModuleInterop": true,
"resolveJsonModule": true,
@@ -18,5 +18,5 @@
"include": [
"src/**/*"
],
- "lib": ["es2015"]
+ "lib": ["es2017"]
}