|
| 1 | +import test from 'ava'; |
| 2 | + |
| 3 | +import { buildAccount, AccountOptions } from './account'; |
| 4 | +import { printContract } from './print'; |
| 5 | + |
| 6 | +import { account } from '.'; |
| 7 | + |
| 8 | +function testAccount(title: string, opts: Partial<AccountOptions>) { |
| 9 | + test(title, t => { |
| 10 | + const c = buildAccount({ |
| 11 | + name: 'MyAccount', |
| 12 | + type: 'stark', |
| 13 | + ...opts, |
| 14 | + }); |
| 15 | + t.snapshot(printContract(c)); |
| 16 | + }); |
| 17 | +} |
| 18 | + |
| 19 | +function testEthAccount(title: string, opts: Partial<AccountOptions>) { |
| 20 | + test(title, t => { |
| 21 | + const c = buildAccount({ |
| 22 | + name: 'MyAccount', |
| 23 | + type: 'eth', |
| 24 | + ...opts, |
| 25 | + }); |
| 26 | + t.snapshot(printContract(c)); |
| 27 | + }); |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Tests external API for equivalence with internal API |
| 32 | + */ |
| 33 | +function testAPIEquivalence(title: string, opts?: AccountOptions) { |
| 34 | + test(title, t => { |
| 35 | + t.is(account.print(opts), printContract(buildAccount({ |
| 36 | + name: 'MyAccount', |
| 37 | + type: 'stark', |
| 38 | + declare: true, |
| 39 | + deploy: true, |
| 40 | + pubkey: true, |
| 41 | + ...opts, |
| 42 | + }))); |
| 43 | + }); |
| 44 | +} |
| 45 | + |
| 46 | +testAccount('default full account, mixin + upgradeable', {}); |
| 47 | + |
| 48 | +testAccount('default full account, mixin + non-upgradeable', { |
| 49 | + upgradeable: false |
| 50 | +}); |
| 51 | + |
| 52 | +testAccount('explicit full account, mixin + upgradeable', { |
| 53 | + name: 'MyAccount', |
| 54 | + type: 'stark', |
| 55 | + declare: true, |
| 56 | + deploy: true, |
| 57 | + pubkey: true, |
| 58 | + upgradeable: true |
| 59 | +}); |
| 60 | + |
| 61 | +testAccount('explicit full account, mixin + non-upgradeable', { |
| 62 | + name: 'MyAccount', |
| 63 | + type: 'stark', |
| 64 | + declare: true, |
| 65 | + deploy: true, |
| 66 | + pubkey: true, |
| 67 | + upgradeable: false |
| 68 | +}); |
| 69 | + |
| 70 | +testAccount('basic account, upgradeable', { |
| 71 | + declare: false, |
| 72 | + deploy: false, |
| 73 | + pubkey: false |
| 74 | +}); |
| 75 | + |
| 76 | +testAccount('basic account, non-upgradeable', { |
| 77 | + declare: false, |
| 78 | + deploy: false, |
| 79 | + pubkey: false, |
| 80 | + upgradeable: false |
| 81 | +}); |
| 82 | + |
| 83 | +testAccount('account declarer', { |
| 84 | + deploy: false, |
| 85 | + pubkey: false |
| 86 | +}); |
| 87 | + |
| 88 | +testAccount('account deployable', { |
| 89 | + declare: false, |
| 90 | + pubkey: false |
| 91 | +}); |
| 92 | + |
| 93 | +testAccount('account public key', { |
| 94 | + declare: false, |
| 95 | + deploy: false, |
| 96 | +}); |
| 97 | + |
| 98 | +testAccount('account declarer, deployable', { |
| 99 | + pubkey: false |
| 100 | +}); |
| 101 | + |
| 102 | +testAccount('account declarer, public key', { |
| 103 | + deploy: false |
| 104 | +}); |
| 105 | + |
| 106 | +testAccount('account deployable, public key', { |
| 107 | + declare: false |
| 108 | +}); |
| 109 | + |
| 110 | +testEthAccount('default full ethAccount, mixin + upgradeable', {}); |
| 111 | + |
| 112 | +testEthAccount('default full ethAccount, mixin + non-upgradeable', { |
| 113 | + upgradeable: false |
| 114 | +}); |
| 115 | + |
| 116 | +testEthAccount('explicit full ethAccount, mixin + upgradeable', { |
| 117 | + name: 'MyAccount', |
| 118 | + type: 'eth', |
| 119 | + declare: true, |
| 120 | + deploy: true, |
| 121 | + pubkey: true, |
| 122 | + upgradeable: true |
| 123 | +}); |
| 124 | + |
| 125 | +testEthAccount('explicit full ethAccount, mixin + non-upgradeable', { |
| 126 | + name: 'MyAccount', |
| 127 | + type: 'eth', |
| 128 | + declare: true, |
| 129 | + deploy: true, |
| 130 | + pubkey: true, |
| 131 | + upgradeable: false |
| 132 | +}); |
| 133 | + |
| 134 | +testEthAccount('basic ethAccount, upgradeable', { |
| 135 | + declare: false, |
| 136 | + deploy: false, |
| 137 | + pubkey: false |
| 138 | +}); |
| 139 | + |
| 140 | +testEthAccount('basic ethAccount, non-upgradeable', { |
| 141 | + declare: false, |
| 142 | + deploy: false, |
| 143 | + pubkey: false, |
| 144 | + upgradeable: false |
| 145 | +}); |
| 146 | + |
| 147 | +testEthAccount('ethAccount declarer', { |
| 148 | + deploy: false, |
| 149 | + pubkey: false |
| 150 | +}); |
| 151 | + |
| 152 | +testEthAccount('ethAccount deployable', { |
| 153 | + declare: false, |
| 154 | + pubkey: false |
| 155 | +}); |
| 156 | + |
| 157 | +testEthAccount('ethAccount public key', { |
| 158 | + declare: false, |
| 159 | + deploy: false, |
| 160 | +}); |
| 161 | + |
| 162 | +testEthAccount('ethAccount declarer, deployable', { |
| 163 | + pubkey: false |
| 164 | +}); |
| 165 | + |
| 166 | +testEthAccount('ethAccount declarer, public key', { |
| 167 | + deploy: false |
| 168 | +}); |
| 169 | + |
| 170 | +testEthAccount('ethAccount deployable, public key', { |
| 171 | + declare: false |
| 172 | +}); |
| 173 | + |
| 174 | +testAPIEquivalence('account API default'); |
| 175 | + |
| 176 | +testAPIEquivalence('account API basic', { |
| 177 | + name: 'CustomAccount', |
| 178 | + type: 'stark', |
| 179 | + declare: false, |
| 180 | + deploy: false, |
| 181 | + pubkey: false, |
| 182 | + upgradeable: false, |
| 183 | +}); |
| 184 | + |
| 185 | +testAPIEquivalence('account API full upgradeable', { |
| 186 | + name: 'CustomAccount', |
| 187 | + type: 'stark', |
| 188 | + declare: true, |
| 189 | + deploy: true, |
| 190 | + pubkey: true, |
| 191 | + upgradeable: true, |
| 192 | +}); |
| 193 | + |
| 194 | +test('account API assert defaults', async t => { |
| 195 | + t.is(account.print(account.defaults), account.print()); |
| 196 | +}); |
0 commit comments