|
1 | 1 | import os
|
2 | 2 | import json
|
3 | 3 | import boto3
|
| 4 | +import re |
4 | 5 | from unittest import TestCase
|
5 | 6 | from me_wallet_token_allhistories_create import MeWalletTokenAllhistoriesCreate
|
6 | 7 | from unittest.mock import patch, MagicMock
|
@@ -57,7 +58,7 @@ def setUp(self):
|
57 | 58 | {
|
58 | 59 | 'user_id': 'user_03',
|
59 | 60 | 'private_eth_address': '0x1234567890123456789012345678901234567890',
|
60 |
| - 'old_private_eth_address': '0x1234567890123456789012345678901234567891' |
| 61 | + 'old_private_eth_address': '0x1111111111111111111111111111111111111111' |
61 | 62 | },
|
62 | 63 | ]
|
63 | 64 | TestsUtil.create_table(self.dynamodb, os.environ['USER_CONFIGURATIONS_TABLE_NAME'], user_configurations_items)
|
@@ -148,10 +149,15 @@ def test_main_ok_with_old_address(self):
|
148 | 149 | user_util_mock.get_cognito_user_info.return_value = {
|
149 | 150 | 'UserAttributes': [{
|
150 | 151 | 'Name': 'custom:private_eth_address',
|
151 |
| - 'Value': '0x1111111111111111111111111111111111111111' |
| 152 | + 'Value': '0x1234567890123456789012345678901234567890' |
152 | 153 | }]
|
153 | 154 | }
|
154 |
| - web3_eth_filter_mock.return_value = PrivateChainEthFilterFakeResponse() |
| 155 | + |
| 156 | + response = PrivateChainEthFilterFakeResponse() |
| 157 | + response_mint_old = PrivateChainEthFilterFakeResponseMintOld() |
| 158 | + response_mint_new = PrivateChainEthFilterFakeResponseMintNew() |
| 159 | + web3_eth_filter_mock.side_effect = [response, response, response_mint_old, |
| 160 | + response, response, response_mint_new] |
155 | 161 |
|
156 | 162 | event = {
|
157 | 163 | 'headers': {
|
@@ -185,13 +191,22 @@ def test_main_ok_with_old_address(self):
|
185 | 191 | Key={'user_id': 'user_03'}
|
186 | 192 | ).get('Item')
|
187 | 193 |
|
188 |
| - notification_type = notification_table.get_item( |
| 194 | + notification_item = notification_table.get_item( |
189 | 195 | Key={'notification_id': 'notification_id_randomhash'}
|
190 |
| - ).get('Item').get('type') |
| 196 | + ).get('Item') |
191 | 197 |
|
192 | 198 | self.assertEqual(len(notification_after), len(notification_before) + 1)
|
193 | 199 | self.assertEqual(unread_notification_manager_after['unread'], True)
|
194 |
| - self.assertEqual(notification_type, 'csvdownload') |
| 200 | + self.assertEqual(notification_item.get('type'), 'csvdownload') |
| 201 | + |
| 202 | + # S3 上のデータ件数を確認 |
| 203 | + s3 = boto3.client('s3', endpoint_url='http://localhost:4572/') |
| 204 | + s3_param = re.match(r'https://(.*).s3-ap-northeast-1.amazonaws.com/(.*)', |
| 205 | + notification_item.get('announce_url')) |
| 206 | + obj = s3.get_object(Bucket=s3_param.group(1), Key=s3_param.group(2))['Body'].read() |
| 207 | + # 対象となるテストデータは 16 件だが、移行時のデータ分が除かれ 15 件になっていること |
| 208 | + # ※ response_mint_new の 2件の内2件が除かれている |
| 209 | + self.assertEqual(len(obj.decode().split('\n')) - 1, 15) |
195 | 210 |
|
196 | 211 | @patch('web3.eth.Eth.getBlock',
|
197 | 212 | MagicMock(return_value={'timestamp': 1546268400}))
|
@@ -347,46 +362,106 @@ def test_ng_migration_checking(self):
|
347 | 362 | class PrivateChainEthFilterFakeResponse:
|
348 | 363 | def get_all_entries(self):
|
349 | 364 | eth_filter_mock_value = MagicMock()
|
350 |
| - eth_filter_mock_value.side_effect = [ |
351 |
| - [{'address': '0x1383B25f9ba231e3a1a1E45c0b5689d778D44AD5', |
352 |
| - 'blockHash': HexBytes('0xf32e073349e4ca49c5e193b161ea1b9ba7dc9c2a9bf1271725c99bb5c690bba7'), |
353 |
| - 'blockNumber': 836877, 'data': '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000', |
354 |
| - 'logIndex': 0, |
355 |
| - 'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), |
356 |
| - HexBytes('0x0000000000000000000000001111111111111111111111111111111111111111'), |
357 |
| - HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000')], |
358 |
| - 'transactionHash': HexBytes('0xf45f335a0bb17d112e870f98218ebd5159e5d7ab9f1739677d7c0b3df4879456'), |
359 |
| - 'transactionIndex': 0, |
360 |
| - 'transactionLogIndex': '0x0', |
361 |
| - 'type': 'mined'}], |
362 |
| - [{'address': '0x1383B25f9ba231e3a1a1E45c0b5689d778D44AD5', |
363 |
| - 'blockHash': HexBytes('0xf32e073349e4ca49c5e193b161ea1b9ba7dc9c2a9bf1271725c99bb5c690bba8'), |
364 |
| - 'blockNumber': 836877, 'data': '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000', |
365 |
| - 'logIndex': 0, |
366 |
| - 'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), |
367 |
| - HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000'), |
368 |
| - HexBytes('0x0000000000000000000000001111111111111111111111111111111111111111')], |
369 |
| - 'transactionHash': HexBytes('0xf45f335a0bb17d112e870f98218ebd5159e5d7ab9f1739677d7c0b3df4879457'), |
370 |
| - 'transactionIndex': 0, |
371 |
| - 'transactionLogIndex': '0x0', |
372 |
| - 'type': 'mined'}], |
373 |
| - [{'address': '0x1383B25f9ba231e3a1a1E45c0b5689d778D44AD5', |
374 |
| - 'blockHash': HexBytes('0xf32e073349e4ca49c5e193b161ea1b9ba7dc9c2a9bf1271725c99bb5c690bba9'), |
375 |
| - 'blockNumber': 836877, 'data': '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000', |
376 |
| - 'logIndex': 0, |
377 |
| - 'topics': [HexBytes('0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885'), |
378 |
| - HexBytes('0x0000000000000000000000001111111111111111111111111111111111111111'), |
379 |
| - HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000')], |
380 |
| - 'transactionHash': HexBytes('0xf45f335a0bb17d112e870f98218ebd5159e5d7ab9f1739677d7c0b3df4879458'), |
381 |
| - 'transactionIndex': 0, |
382 |
| - 'transactionLogIndex': '0x0', |
383 |
| - 'type': 'mined'}], |
| 365 | + eth_filter_mock_value.return_value = [ |
| 366 | + {'address': '0x1383B25f9ba231e3a1a1E45c0b5689d778D44AD5', |
| 367 | + 'blockHash': HexBytes('0xf32e073349e4ca49c5e193b161ea1b9ba7dc9c2a9bf1271725c99bb5c690bba7'), |
| 368 | + 'blockNumber': 836877, 'data': '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000', |
| 369 | + 'logIndex': 0, |
| 370 | + 'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), |
| 371 | + HexBytes('0x0000000000000000000000001111111111111111111111111111111111111111'), |
| 372 | + HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000')], |
| 373 | + 'transactionHash': HexBytes('0xf45f335a0bb17d112e870f98218ebd5159e5d7ab9f1739677d7c0b3df4879456'), |
| 374 | + 'transactionIndex': 0, |
| 375 | + 'transactionLogIndex': '0x0', |
| 376 | + 'type': 'mined'}, |
| 377 | + {'address': '0x1383B25f9ba231e3a1a1E45c0b5689d778D44AD5', |
| 378 | + 'blockHash': HexBytes('0xf32e073349e4ca49c5e193b161ea1b9ba7dc9c2a9bf1271725c99bb5c690bba8'), |
| 379 | + 'blockNumber': 836877, 'data': '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000', |
| 380 | + 'logIndex': 0, |
| 381 | + 'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), |
| 382 | + HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000'), |
| 383 | + HexBytes('0x0000000000000000000000001111111111111111111111111111111111111111')], |
| 384 | + 'transactionHash': HexBytes('0xf45f335a0bb17d112e870f98218ebd5159e5d7ab9f1739677d7c0b3df4879457'), |
| 385 | + 'transactionIndex': 0, |
| 386 | + 'transactionLogIndex': '0x0', |
| 387 | + 'type': 'mined'}, |
| 388 | + {'address': '0x1383B25f9ba231e3a1a1E45c0b5689d778D44AD5', |
| 389 | + 'blockHash': HexBytes('0xf32e073349e4ca49c5e193b161ea1b9ba7dc9c2a9bf1271725c99bb5c690bba9'), |
| 390 | + 'blockNumber': 836877, 'data': '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000', |
| 391 | + 'logIndex': 0, |
| 392 | + 'topics': [HexBytes('0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885'), |
| 393 | + HexBytes('0x0000000000000000000000001111111111111111111111111111111111111111'), |
| 394 | + HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000')], |
| 395 | + 'transactionHash': HexBytes('0xf45f335a0bb17d112e870f98218ebd5159e5d7ab9f1739677d7c0b3df4879458'), |
| 396 | + 'transactionIndex': 0, |
| 397 | + 'transactionLogIndex': '0x0', |
| 398 | + 'type': 'mined'}, |
384 | 399 | ]
|
385 | 400 | return eth_filter_mock_value()
|
386 | 401 |
|
387 | 402 |
|
388 |
| -class PrivateChainEthFilterFakeResponseWithSeveralData: |
| 403 | +class PrivateChainEthFilterFakeResponseMintOld: |
| 404 | + def get_all_entries(self): |
| 405 | + eth_filter_mock_value = MagicMock() |
| 406 | + eth_filter_mock_value.return_value = [ |
| 407 | + {'address': '0x1383B25f9ba231e3a1a1E45c0b5689d778D44AD5', |
| 408 | + 'blockHash': HexBytes('0xf32e073349e4ca49c5e193b161ea1b9ba7dc9c2a9bf1271725c99bb5c690bba7'), |
| 409 | + 'blockNumber': 836877, 'data': '0x00000000000000000000000000000000000000000000000029A2241AF62C0000', |
| 410 | + 'logIndex': 0, |
| 411 | + 'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), |
| 412 | + HexBytes('0x0000000000000000000000001111111111111111111111111111111111111111'), |
| 413 | + HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000')], |
| 414 | + 'transactionHash': HexBytes('0xf45f335a0bb17d112e870f98218ebd5159e5d7ab9f1739677d7c0b3df4879456'), |
| 415 | + 'transactionIndex': 0, |
| 416 | + 'transactionLogIndex': '0x0', |
| 417 | + 'type': 'mined'}, |
| 418 | + {'address': '0x1383B25f9ba231e3a1a1E45c0b5689d778D44AD5', |
| 419 | + 'blockHash': HexBytes('0xf32e073349e4ca49c5e193b161ea1b9ba7dc9c2a9bf1271725c99bb5c690bba9'), |
| 420 | + 'blockNumber': 836877, 'data': '0x00000000000000000000000000000000000000000000000029A2241AF62C0000', |
| 421 | + 'logIndex': 0, |
| 422 | + 'topics': [HexBytes('0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885'), |
| 423 | + HexBytes('0x0000000000000000000000001111111111111111111111111111111111111111'), |
| 424 | + HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000')], |
| 425 | + 'transactionHash': HexBytes('0xf45f335a0bb17d112e870f98218ebd5159e5d7ab9f1739677d7c0b3df4879458'), |
| 426 | + 'transactionIndex': 0, |
| 427 | + 'transactionLogIndex': '0x0', |
| 428 | + 'type': 'mined'} |
| 429 | + ] |
| 430 | + return eth_filter_mock_value() |
| 431 | + |
389 | 432 |
|
| 433 | +class PrivateChainEthFilterFakeResponseMintNew: |
| 434 | + def get_all_entries(self): |
| 435 | + eth_filter_mock_value = MagicMock() |
| 436 | + # 移行対象のデータが存在する返り値を設定 |
| 437 | + eth_filter_mock_value.return_value = [ |
| 438 | + {'address': '0x1383B25f9ba231e3a1a1E45c0b5689d778D44AD5', |
| 439 | + 'blockHash': HexBytes('0xf32e073349e4ca49c5e193b161ea1b9ba7dc9c2a9bf1271725c99bb5c690bba7'), |
| 440 | + 'blockNumber': 836877, 'data': '0x0000000000000000000000000000000000000000000000003782DACE9D900000', |
| 441 | + 'logIndex': 0, |
| 442 | + 'topics': [HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'), |
| 443 | + HexBytes('0x0000000000000000000000001234567890123456789012345678901234567890'), |
| 444 | + HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000')], |
| 445 | + 'transactionHash': HexBytes('0xf45f335a0bb17d112e870f98218ebd5159e5d7ab9f1739677d7c0b3df4879456'), |
| 446 | + 'transactionIndex': 0, |
| 447 | + 'transactionLogIndex': '0x0', |
| 448 | + 'type': 'mined'}, |
| 449 | + {'address': '0x1383B25f9ba231e3a1a1E45c0b5689d778D44AD5', |
| 450 | + 'blockHash': HexBytes('0xf32e073349e4ca49c5e193b161ea1b9ba7dc9c2a9bf1271725c99bb5c690bba9'), |
| 451 | + 'blockNumber': 836877, 'data': '0x0000000000000000000000000000000000000000000000003782DACE9D900000', |
| 452 | + 'logIndex': 0, |
| 453 | + 'topics': [HexBytes('0x0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d4121396885'), |
| 454 | + HexBytes('0x0000000000000000000000001234567890123456789012345678901234567890'), |
| 455 | + HexBytes('0x0000000000000000000000000000000000000000000000000000000000000000')], |
| 456 | + 'transactionHash': HexBytes('0xf45f335a0bb17d112e870f98218ebd5159e5d7ab9f1739677d7c0b3df4879458'), |
| 457 | + 'transactionIndex': 0, |
| 458 | + 'transactionLogIndex': '0x0', |
| 459 | + 'type': 'mined'}, |
| 460 | + ] |
| 461 | + return eth_filter_mock_value() |
| 462 | + |
| 463 | + |
| 464 | +class PrivateChainEthFilterFakeResponseWithSeveralData: |
390 | 465 | def get_all_entries(self):
|
391 | 466 | eth_filter_mock_value = MagicMock()
|
392 | 467 | eth_filter_mock_value.side_effect = [
|
|
0 commit comments