Beispiel #1
0
    def assert_bad_request(self, params):
        target_function = MeWalletTokenAllhistoriesCreate(params, {},
                                                          self.dynamodb,
                                                          cognito=None)
        response = target_function.main()

        self.assertEqual(response['statusCode'], 400)
def lambda_handler(event, context):
    me_wallet_token_allhistories_create = MeWalletTokenAllhistoriesCreate(
        event=event,
        context=context,
        dynamodb=dynamodb,
        s3=s3,
        cognito=cognito)
    return me_wallet_token_allhistories_create.main()
Beispiel #3
0
    def test_main_ok(self):
        with patch('web3.eth.Eth.filter') as web3_eth_filter_mock, \
                patch('me_wallet_token_allhistories_create.UserUtil') as user_util_mock:
            user_util_mock.get_cognito_user_info.return_value = {
                'UserAttributes': [{
                    'Name':
                    'custom:private_eth_address',
                    'Value':
                    '0x1111111111111111111111111111111111111111'
                }]
            }
            web3_eth_filter_mock.return_value = PrivateChainEthFilterFakeResponse(
            )

            event = {
                'headers': {
                    'Authorization': 'idtoken_dummy'
                },
                'requestContext': {
                    'authorizer': {
                        'claims': {
                            'cognito:username': '******',
                            'cognito-identity': 'ap-northeast-1:hogehoge',
                            'custom:private_eth_address':
                            '0x1111111111111111111111111111111111111111',
                            'phone_number_verified': 'true',
                            'email_verified': 'true'
                        }
                    }
                }
            }

            unread_notification_manager_table = self.dynamodb.Table(
                os.environ['UNREAD_NOTIFICATION_MANAGER_TABLE_NAME'])

            notification_table = self.dynamodb.Table(
                os.environ['NOTIFICATION_TABLE_NAME'])
            notification_before = notification_table.scan()['Items']

            response = MeWalletTokenAllhistoriesCreate(event, {},
                                                       dynamodb=self.dynamodb,
                                                       s3=self.s3).main()
            self.assertEqual(response['statusCode'], 200)

            notification_after = notification_table.scan()['Items']

            unread_notification_manager_after = unread_notification_manager_table.get_item(
                Key={
                    'user_id': 'user_01'
                }).get('Item')

            notification_type = notification_table.get_item(
                Key={
                    'notification_id': 'notification_id_randomhash'
                }).get('Item').get('type')

            self.assertEqual(len(notification_after),
                             len(notification_before) + 1)
            self.assertEqual(unread_notification_manager_after['unread'], True)
            self.assertEqual(notification_type, 'csvdownload')
Beispiel #4
0
    def test_ng_migration_checking(self):
        event = {
            'requestContext': {
                'authorizer': {
                    'claims': {
                        'cognito:username': '******',
                        'cognito-identity': 'ap-northeast-1:hogehoge',
                        'custom:private_eth_address':
                        '0x1111111111111111111111111111111111111111',
                        'phone_number_verified': 'true',
                        'email_verified': 'true'
                    }
                }
            }
        }

        response = MeWalletTokenAllhistoriesCreate(event, {},
                                                   dynamodb=self.dynamodb,
                                                   s3=self.s3).main()
        self.assertEqual(response['statusCode'], 403)
        self.assertEqual(
            json.loads(response['body'])['message'],
            'Not exists private_eth_address')
Beispiel #5
0
    def test_ok_with_no_data(self):
        with patch('web3.eth.Eth.filter') as web3_eth_filter_with_no_data_mock, \
                patch('me_wallet_token_allhistories_create.UserUtil') as user_util_mock:
            user_util_mock.get_cognito_user_info.return_value = {
                'UserAttributes': [{
                    'Name':
                    'custom:private_eth_address',
                    'Value':
                    '0x1111111111111111111111111111111111111111'
                }]
            }
            web3_eth_filter_with_no_data_mock.return_value = PrivateChainEthFilterFakeResponseWithNoData(
            )

            event = {
                'headers': {
                    'Authorization': 'idtoken_dummy'
                },
                'requestContext': {
                    'authorizer': {
                        'claims': {
                            'cognito:username': '******',
                            'cognito-identity': 'ap-northeast-1:hogehoge',
                            'custom:private_eth_address':
                            '0x1111111111111111111111111111111111111111',
                            'phone_number_verified': 'true',
                            'email_verified': 'true'
                        }
                    }
                }
            }

            response = MeWalletTokenAllhistoriesCreate(event, {},
                                                       dynamodb=self.dynamodb,
                                                       s3=self.s3).main()
            self.assertEqual(response['statusCode'], 404)
Beispiel #6
0
    def test_add_type_ok(self):
        with patch('me_wallet_token_allhistories_create.UserUtil'
                   ) as user_util_mock:
            user_util_mock.get_cognito_user_info.return_value = {
                'UserAttributes': [{
                    'Name':
                    'custom:private_eth_address',
                    'Value':
                    '0x1111111111111111111111111111111111111111'
                }]
            }

            event = {
                'headers': {
                    'Authorization': 'idtoken_dummy'
                },
                'requestContext': {
                    'authorizer': {
                        'claims': {
                            'cognito:username': '******',
                            'custom:private_eth_address':
                            '0x1111111111111111111111111111111111111abc',
                            'cognito-identity': 'ap-northeast-1:hogehoge',
                            'phone_number_verified': 'true',
                            'email_verified': 'true'
                        }
                    }
                }
            }

            user_eoa = event['requestContext']['authorizer']['claims'][
                'custom:private_eth_address']
            MeWalletTokenAllhistoriesCreate.eoa = user_eoa
            alis_bridge_contract_address = os.environ[
                'PRIVATE_CHAIN_BRIDGE_ADDRESS']
            burn_address = os.environ['BURN_ADDRESS']

            response = MeWalletTokenAllhistoriesCreate(
                event, {},
                self.dynamodb).add_type(user_eoa, alis_bridge_contract_address,
                                        user_eoa.upper())
            self.assertEqual(response, 'withdraw')
            response = MeWalletTokenAllhistoriesCreate(event, {},
                                                       self.dynamodb).add_type(
                                                           user_eoa,
                                                           '0x' + burn_address,
                                                           user_eoa)
            self.assertEqual(response, 'pool')
            response = MeWalletTokenAllhistoriesCreate(
                event, {}, self.dynamodb).add_type(
                    user_eoa, '0x0123456789012345678901234567890123456789',
                    user_eoa)
            self.assertEqual(response, 'give')
            response = MeWalletTokenAllhistoriesCreate(
                event, {}, self.dynamodb).add_type(
                    user_eoa, '0x0000000000000000000000000000000000000000',
                    user_eoa)
            self.assertEqual(response, 'burn')
            response = MeWalletTokenAllhistoriesCreate(
                event, {},
                self.dynamodb).add_type(alis_bridge_contract_address, user_eoa,
                                        user_eoa)
            self.assertEqual(response, 'deposit')
            response = MeWalletTokenAllhistoriesCreate(
                event, {}, self.dynamodb).add_type('---', user_eoa, user_eoa)
            self.assertEqual(response, 'get by like')
            response = MeWalletTokenAllhistoriesCreate(
                event, {}, self.dynamodb).add_type(
                    '0x0123456789012345678901234567890123456789', user_eoa,
                    user_eoa)
            self.assertEqual(response, 'get from user')
            response = MeWalletTokenAllhistoriesCreate(
                event, {}, self.dynamodb).add_type('---', None, user_eoa)
            self.assertEqual(response, 'unknown')
Beispiel #7
0
    def test_main_ok_with_old_address(self):
        with patch('web3.eth.Eth.filter') as web3_eth_filter_mock, \
                patch('me_wallet_token_allhistories_create.UserUtil') as user_util_mock:
            user_util_mock.get_cognito_user_info.return_value = {
                'UserAttributes': [{
                    'Name':
                    'custom:private_eth_address',
                    'Value':
                    '0x1234567890123456789012345678901234567890'
                }]
            }

            response = PrivateChainEthFilterFakeResponse()
            response_mint_old = PrivateChainEthFilterFakeResponseMintOld()
            response_mint_new = PrivateChainEthFilterFakeResponseMintNew()
            web3_eth_filter_mock.side_effect = [
                response, response, response_mint_old, response, response,
                response_mint_new
            ]

            event = {
                'headers': {
                    'Authorization': 'idtoken_dummy'
                },
                'requestContext': {
                    'authorizer': {
                        'claims': {
                            'cognito:username': '******',
                            'cognito-identity': 'ap-northeast-1:hogehoge',
                            'custom:private_eth_address':
                            '0x1111111111111111111111111111111111111111',
                            'phone_number_verified': 'true',
                            'email_verified': 'true'
                        }
                    }
                }
            }

            unread_notification_manager_table = self.dynamodb.Table(
                os.environ['UNREAD_NOTIFICATION_MANAGER_TABLE_NAME'])

            notification_table = self.dynamodb.Table(
                os.environ['NOTIFICATION_TABLE_NAME'])
            notification_before = notification_table.scan()['Items']

            response = MeWalletTokenAllhistoriesCreate(event, {},
                                                       dynamodb=self.dynamodb,
                                                       s3=self.s3).main()
            self.assertEqual(response['statusCode'], 200)

            notification_after = notification_table.scan()['Items']

            unread_notification_manager_after = unread_notification_manager_table.get_item(
                Key={
                    'user_id': 'user_03'
                }).get('Item')

            notification_item = notification_table.get_item(
                Key={
                    'notification_id': 'notification_id_randomhash'
                }).get('Item')

            self.assertEqual(len(notification_after),
                             len(notification_before) + 1)
            self.assertEqual(unread_notification_manager_after['unread'], True)
            self.assertEqual(notification_item.get('type'), 'csvdownload')

            # S3 上のデータ件数を確認
            s3 = boto3.client('s3', endpoint_url='http://localhost:4572/')
            s3_param = re.match(
                r'https://(.*).s3-ap-northeast-1.amazonaws.com/(.*)',
                notification_item.get('announce_url'))
            obj = s3.get_object(Bucket=s3_param.group(1),
                                Key=s3_param.group(2))['Body'].read()
            # 対象となるテストデータは 16 件だが、移行時のデータ分が除かれ 15 件になっていること
            # ※ response_mint_new の 2件の内2件が除かれている
            self.assertEqual(len(obj.decode().split('\n')) - 1, 15)